-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathregex.po
2152 lines (1867 loc) · 125 KB
/
regex.po
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001-2023, Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# df2dc1c92e792f7ae8417c51df43db8f_594d92a <0f49be28017426edb1db1a2ab6e67088_717605>, 2019
# 操旭 <caoxu3000@126.com>, 2019
# ww song <sww4718168@gmail.com>, 2019
# dannyvi <dannyvis@icloud.com>, 2019
# Alpha Du <alphanow@gmail.com>, 2019
# Freesand Leo <yuqinju@163.com>, 2023
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.7\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-03-03 14:41+0000\n"
"PO-Revision-Date: 2019-09-01 03:38+0000\n"
"Last-Translator: Freesand Leo <yuqinju@163.com>, 2023\n"
"Language-Team: Chinese (China) (https://www.transifex.com/python-doc/teams/5390/zh_CN/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: zh_CN\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:5
msgid "Regular Expression HOWTO"
msgstr "正则表达式HOWTO"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:0
msgid "Author"
msgstr "作者"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:7
msgid "A.M. Kuchling <amk@amk.ca>"
msgstr "A.M. Kuchling <amk@amk.ca>"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rstNone
msgid "Abstract"
msgstr "摘要"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:18
msgid ""
"This document is an introductory tutorial to using regular expressions in "
"Python with the :mod:`re` module. It provides a gentler introduction than "
"the corresponding section in the Library Reference."
msgstr "本文档是在Python中使用 :mod:`re` 模块使用正则表达式的入门教程。 它提供了比“标准库参考”中相应部分更平和的介绍。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:24
msgid "Introduction"
msgstr "概述"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:26
msgid ""
"Regular expressions (called REs, or regexes, or regex patterns) are "
"essentially a tiny, highly specialized programming language embedded inside "
"Python and made available through the :mod:`re` module. Using this little "
"language, you specify the rules for the set of possible strings that you "
"want to match; this set might contain English sentences, or e-mail "
"addresses, or TeX commands, or anything you like. You can then ask "
"questions such as \"Does this string match the pattern?\", or \"Is there a "
"match for the pattern anywhere in this string?\". You can also use REs to "
"modify a string or to split it apart in various ways."
msgstr ""
"正则表达式(称为RE,或正则,或正则表达式模式)本质上是嵌入在Python中的一种微小的、高度专业化的编程语言,可通过 :mod:`re` 模块获得。 "
"使用这种小语言,你可以为要匹配的可能字符串集指定规则;此集可能包含英语句子,电子邮件地址,TeX命令或你喜欢的任何内容。 "
"然后,您可以询问诸如“此字符串是否与模式匹配?”或“此字符串中的模式是否匹配?”等问题。 你还可以使用正则修改字符串或以各种方式将其拆分。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:35
msgid ""
"Regular expression patterns are compiled into a series of bytecodes which "
"are then executed by a matching engine written in C. For advanced use, it "
"may be necessary to pay careful attention to how the engine will execute a "
"given RE, and write the RE in a certain way in order to produce bytecode "
"that runs faster. Optimization isn't covered in this document, because it "
"requires that you have a good understanding of the matching engine's "
"internals."
msgstr ""
"正则表达式模式被编译成一系列字节码,然后由用 C "
"编写的匹配引擎执行。对于高级用途,可能需要特别注意引擎如何执行给定的正则,并将正则写入以某种方式生成运行速度更快的字节码。 "
"本文档未涉及优化,因为它要求你充分了解匹配引擎的内部结构。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:42
msgid ""
"The regular expression language is relatively small and restricted, so not "
"all possible string processing tasks can be done using regular expressions."
" There are also tasks that *can* be done with regular expressions, but the "
"expressions turn out to be very complicated. In these cases, you may be "
"better off writing Python code to do the processing; while Python code will "
"be slower than an elaborate regular expression, it will also probably be "
"more understandable."
msgstr ""
"正则表达式语言相对较小且受限制,因此并非所有可能的字符串处理任务都可以使用正则表达式完成。 还有一些任务 *可以* "
"用正则表达式完成,但表达式变得非常复杂。 在这些情况下,你最好编写 Python 代码来进行处理;虽然 Python "
"代码比精心设计的正则表达式慢,但它也可能更容易理解。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:51
msgid "Simple Patterns"
msgstr "简单模式"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:53
msgid ""
"We'll start by learning about the simplest possible regular expressions. "
"Since regular expressions are used to operate on strings, we'll begin with "
"the most common task: matching characters."
msgstr "我们首先要了解最简单的正则表达式。 由于正则表达式用于对字符串进行操作,因此我们将从最常见的任务开始:匹配字符。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:57
msgid ""
"For a detailed explanation of the computer science underlying regular "
"expressions (deterministic and non-deterministic finite automata), you can "
"refer to almost any textbook on writing compilers."
msgstr "有关正则表达式(确定性和非确定性有限自动机)的计算机科学的详细解释,你可以参考几乎所有有关编写编译器的教科书。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:63
msgid "Matching Characters"
msgstr "匹配字符"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:65
msgid ""
"Most letters and characters will simply match themselves. For example, the "
"regular expression ``test`` will match the string ``test`` exactly. (You "
"can enable a case-insensitive mode that would let this RE match ``Test`` or "
"``TEST`` as well; more about this later.)"
msgstr ""
"大多数字母和字符只会匹配自己。 例如,正则表达式 ``test`` 将完全匹配字符串 ``test`` 。 "
"(你可以启用一个不区分大小写的模式,让这个正则匹配 ``Test`` 或 ``TEST``,稍后会详细介绍。)"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:70
msgid ""
"There are exceptions to this rule; some characters are special "
":dfn:`metacharacters`, and don't match themselves. Instead, they signal "
"that some out-of-the-ordinary thing should be matched, or they affect other "
"portions of the RE by repeating them or changing their meaning. Much of "
"this document is devoted to discussing various metacharacters and what they "
"do."
msgstr ""
"这条规则有例外;一些字符是特殊的 :dfn:`metacharacters` ,并且不匹配自己。 "
"相反,它们表示应该匹配一些与众不同的东西,或者通过重复它们或改变它们的含义来影响正则的其他部分。 本文档的大部分内容都致力于讨论各种元字符及其功能。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:76
msgid ""
"Here's a complete list of the metacharacters; their meanings will be "
"discussed in the rest of this HOWTO."
msgstr "这是元字符的完整列表;它们的意思将在本HOWTO的其余部分讨论。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:83
msgid ""
"The first metacharacters we'll look at are ``[`` and ``]``. They're used for"
" specifying a character class, which is a set of characters that you wish to"
" match. Characters can be listed individually, or a range of characters can"
" be indicated by giving two characters and separating them by a ``'-'``. "
"For example, ``[abc]`` will match any of the characters ``a``, ``b``, or "
"``c``; this is the same as ``[a-c]``, which uses a range to express the same"
" set of characters. If you wanted to match only lowercase letters, your RE "
"would be ``[a-z]``."
msgstr ""
"我们将看到的第一个元字符是 ``[``和``]``。 它们用于指定字符类,它是你希望匹配的一组字符。 可以单独列出字符,也可以通过给出两个字符并用 "
"``'-'`` 标记将它们分开来表示一系列字符。 例如,``[abc]`` 将匹配任何字符 ``a``、``b`` 或 ``c``; 这与 "
"``[a-c]`` 相同,它使用一个范围来表示同一组字符。 如果你只想匹配小写字母,你的正则是 ``[a-z]``。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:92
msgid ""
"Metacharacters are not active inside classes. For example, ``[akm$]`` will "
"match any of the characters ``'a'``, ``'k'``, ``'m'``, or ``'$'``; ``'$'`` "
"is usually a metacharacter, but inside a character class it's stripped of "
"its special nature."
msgstr ""
"字符类中的元字符不生效。 例如,``[akm$]`` 将匹配``'a'``,``'k'``、``'m'``或``'$'`` 中的任意字符;``'$'``"
" 通常是一个元字符,但在一个字符类中它被剥夺了特殊性。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:97
msgid ""
"You can match the characters not listed within the class by "
":dfn:`complementing` the set. This is indicated by including a ``'^'`` as "
"the first character of the class. For example, ``[^5]`` will match any "
"character except ``'5'``. If the caret appears elsewhere in a character "
"class, it does not have special meaning. For example: ``[5^]`` will match "
"either a ``'5'`` or a ``'^'``."
msgstr ""
"你可以通过以下方式匹配 :dfn:`complementing` 设置的字符类中未列出的字符。这通过包含一个 ``'^'`` "
"作为该类的第一个字符来表示。 例如,``[^5]`` 将匹配除 ``'5'`` 之外的任何字符。 如果插入符出现在字符类的其他位置,则它没有特殊含义。 "
"例如:``[5^]`` 将匹配 ``'5'`` 或 ``'^'``。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:103
msgid ""
"Perhaps the most important metacharacter is the backslash, ``\\``. As in "
"Python string literals, the backslash can be followed by various characters "
"to signal various special sequences. It's also used to escape all the "
"metacharacters so you can still match them in patterns; for example, if you "
"need to match a ``[`` or ``\\``, you can precede them with a backslash to "
"remove their special meaning: ``\\[`` or ``\\\\``."
msgstr ""
"也许最重要的元字符是反斜杠,``\\``。 与 Python "
"字符串文字一样,反斜杠后面可以跟各种字符,以指示各种特殊序列。它也用于转义所有元字符,因此您仍然可以在模式中匹配它们;例如,如果你需要匹配 ``[`` "
"或 ``\\``,你可以在它们前面加一个反斜杠来移除它们的特殊含义:``\\[`` 或 ``\\\\``。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:110
msgid ""
"Some of the special sequences beginning with ``'\\'`` represent predefined "
"sets of characters that are often useful, such as the set of digits, the set"
" of letters, or the set of anything that isn't whitespace."
msgstr "一些以 ``'\\'`` 开头的特殊序列表示通常有用的预定义字符集,例如数字集、字母集或任何非空格的集合。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:115
msgid ""
"Let's take an example: ``\\w`` matches any alphanumeric character. If the "
"regex pattern is expressed in bytes, this is equivalent to the class "
"``[a-zA-Z0-9_]``. If the regex pattern is a string, ``\\w`` will match all "
"the characters marked as letters in the Unicode database provided by the "
":mod:`unicodedata` module. You can use the more restricted definition of "
"``\\w`` in a string pattern by supplying the :const:`re.ASCII` flag when "
"compiling the regular expression."
msgstr ""
"让我们举一个例子:``\\w`` 匹配任何字母数字字符。 如果正则表达式模式以字节类表示,这相当于类 "
"``[a-zA-Z0-9_]``。如果正则表达式是一个字符串,``\\w`` 将匹配由 :mod:`unicodedata` 模块提供的 Unicode"
" 数据库中标记为字母的所有字符。 通过在编译正则表达式时提供 :const:`re.ASCII` 标志,可以在字符串模式中使用更为受限制的 "
"``\\w`` 定义。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:123
msgid ""
"The following list of special sequences isn't complete. For a complete list "
"of sequences and expanded class definitions for Unicode string patterns, see"
" the last part of :ref:`Regular Expression Syntax <re-syntax>` in the "
"Standard Library reference. In general, the Unicode versions match any "
"character that's in the appropriate category in the Unicode database."
msgstr ""
"以下特殊序列列表不完整。 有关 Unicode 字符串模式的序列和扩展类定义的完整列表,请参阅标准库参考中的最后一部分 :ref:`正则表达式语法 "
"<re-syntax>` 。通常,Unicode 版本匹配 Unicode 数据库中相应类别中的任何字符。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:131
msgid "``\\d``"
msgstr "``\\d``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:131
msgid "Matches any decimal digit; this is equivalent to the class ``[0-9]``."
msgstr "匹配任何十进制数字;这等价于类 ``[0-9]``。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:134
msgid "``\\D``"
msgstr "``\\D``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:134
msgid ""
"Matches any non-digit character; this is equivalent to the class ``[^0-9]``."
msgstr "匹配任何非数字字符;这等价于类 ``[^0-9]``。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:138
msgid "``\\s``"
msgstr "``\\s``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:137
msgid ""
"Matches any whitespace character; this is equivalent to the class ``[ "
"\\t\\n\\r\\f\\v]``."
msgstr "匹配任何空白字符;这等价于类 ``[ \\t\\n\\r\\f\\v]``。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:142
msgid "``\\S``"
msgstr "``\\S``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:141
msgid ""
"Matches any non-whitespace character; this is equivalent to the class ``[^ "
"\\t\\n\\r\\f\\v]``."
msgstr "匹配任何非空白字符;这相当于类 ``[^ \\t\\n\\r\\f\\v]``。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:146
msgid "``\\w``"
msgstr "``\\w``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:145
msgid ""
"Matches any alphanumeric character; this is equivalent to the class "
"``[a-zA-Z0-9_]``."
msgstr "匹配任何字母与数字字符;这相当于类 ``[a-zA-Z0-9_]``。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:150
msgid "``\\W``"
msgstr "``\\W``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:149
msgid ""
"Matches any non-alphanumeric character; this is equivalent to the class "
"``[^a-zA-Z0-9_]``."
msgstr "匹配任何非字母与数字字符;这相当于类 ``[^a-zA-Z0-9_]``。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:152
msgid ""
"These sequences can be included inside a character class. For example, "
"``[\\s,.]`` is a character class that will match any whitespace character, "
"or ``','`` or ``'.'``."
msgstr "这些序列可以包含在字符类中。 例如,``[\\s,.]`` 是一个匹配任何空格字符的字符类或者 ``','`` ,或 ``'.'``。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:156
msgid ""
"The final metacharacter in this section is ``.``. It matches anything "
"except a newline character, and there's an alternate mode "
"(:const:`re.DOTALL`) where it will match even a newline. ``.`` is often "
"used where you want to match \"any character\"."
msgstr ""
"本节的最后一个元字符是 ``.`` 。 它匹配除换行符之外的任何内容,并且有一个可选模式( :const:`re.DOTALL` )甚至可以匹配换行符。"
" ``.`` 常用于你想匹配“任何字符”的地方。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:163
msgid "Repeating Things"
msgstr "重复"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:165
msgid ""
"Being able to match varying sets of characters is the first thing regular "
"expressions can do that isn't already possible with the methods available on"
" strings. However, if that was the only additional capability of regexes, "
"they wouldn't be much of an advance. Another capability is that you can "
"specify that portions of the RE must be repeated a certain number of times."
msgstr ""
"能够匹配不同的字符集合是正则表达式可以做的第一件事,这对于字符串可用方法来说是不可能的。 "
"但是,如果这是正则表达式的唯一额外功能,那么它们就不会有太大的优势。 另一个功能是你可以指定正则的某些部分必须重复一定次数。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:171
msgid ""
"The first metacharacter for repeating things that we'll look at is ``*``. "
"``*`` doesn't match the literal character ``'*'``; instead, it specifies "
"that the previous character can be matched zero or more times, instead of "
"exactly once."
msgstr ""
"重复中我们要了解的第一个元字符是 ``*``。 ``*`` 与字面字符 ``'*'`` "
"不匹配;相反,它指定前一个字符可以匹配零次或多次,而不是恰好一次。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:175
msgid ""
"For example, ``ca*t`` will match ``'ct'`` (0 ``'a'`` characters), ``'cat'`` "
"(1 ``'a'``), ``'caaat'`` (3 ``'a'`` characters), and so forth."
msgstr ""
"例如,``ca*t`` 将匹配 ``'ct'`` (0个 ``'a'`` 字符),``'cat'`` (1个``'a'``),` `'caaat'`` "
"(3个 ``'a'`` 字符),等等。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:178
msgid ""
"Repetitions such as ``*`` are :dfn:`greedy`; when repeating a RE, the "
"matching engine will try to repeat it as many times as possible. If later "
"portions of the pattern don't match, the matching engine will then back up "
"and try again with fewer repetitions."
msgstr ""
"类似 ``*`` 这样的重复是 :dfn:`贪婪的`;当重复正则时,匹配引擎将尝试尽可能多地重复它。 "
"如果模式的后续部分不匹配,则匹配引擎将回退并以较少的重复次数再次尝试。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:183
msgid ""
"A step-by-step example will make this more obvious. Let's consider the "
"expression ``a[bcd]*b``. This matches the letter ``'a'``, zero or more "
"letters from the class ``[bcd]``, and finally ends with a ``'b'``. Now "
"imagine matching this RE against the string ``'abcbd'``."
msgstr ""
"一个逐步的例子将使这更加明显。 让我们考虑表达式 ``a[bcd]*b``。 这个正则匹配字母 ``'a'``,类 ``[bcd]`` "
"中的零或多个字母,最后以 ``'b'`` 结尾。 现在想象一下这个正则与字符串 ``'abcbd'`` 匹配。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:189
msgid "Step"
msgstr "步骤"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:189
msgid "Matched"
msgstr "匹配"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:189
msgid "Explanation"
msgstr "解释"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:191
msgid "1"
msgstr "1"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:191
msgid "``a``"
msgstr "``a``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:191
msgid "The ``a`` in the RE matches."
msgstr "正则中的 ``a`` 匹配。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:193
msgid "2"
msgstr "2"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:193
msgid "``abcbd``"
msgstr "``abcbd``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:193
msgid ""
"The engine matches ``[bcd]*``, going as far as it can, which is to the end "
"of the string."
msgstr "引擎尽可能多地匹配 ``[bcd]*`` ,直到字符串结束。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:197
msgid "3"
msgstr "3"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:197
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:205
msgid "*Failure*"
msgstr "*失败*"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:197
msgid ""
"The engine tries to match ``b``, but the current position is at the end of "
"the string, so it fails."
msgstr "引擎尝试匹配 ``b`` ,但是当前位置位于字符串结束,所以匹配失败。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:202
msgid "4"
msgstr "4"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:202
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:213
msgid "``abcb``"
msgstr "``abcb``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:202
msgid "Back up, so that ``[bcd]*`` matches one less character."
msgstr "回退一次,``[bcd]*`` 少匹配一个字符。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:205
msgid "5"
msgstr "5"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:205
msgid ""
"Try ``b`` again, but the current position is at the last character, which is"
" a ``'d'``."
msgstr "再次尝试匹配 ``b`` , 但是当前位置是最后一个字符 ``'d'`` 。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:209
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:213
msgid "6"
msgstr "6"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:209
msgid "``abc``"
msgstr "``abc``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:209
msgid "Back up again, so that ``[bcd]*`` is only matching ``bc``."
msgstr "再次回退,所以 ``[bcd]*`` 只匹配 ``bc`` 。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:213
msgid ""
"Try ``b`` again. This time the character at the current position is "
"``'b'``, so it succeeds."
msgstr "再试一次 ``b`` 。 这次当前位置的字符是 ``'b'`` ,所以它成功了。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:219
msgid ""
"The end of the RE has now been reached, and it has matched ``'abcb'``. This"
" demonstrates how the matching engine goes as far as it can at first, and if"
" no match is found it will then progressively back up and retry the rest of "
"the RE again and again. It will back up until it has tried zero matches for"
" ``[bcd]*``, and if that subsequently fails, the engine will conclude that "
"the string doesn't match the RE at all."
msgstr ""
"正则现在已经结束了,它已经匹配了 ``'abcb'``。 这演示了匹配引擎最初如何进行,如果没有找到匹配,它将逐步回退并一次又一次地重试正则的其余部分。"
" 它将回退,直到它为 ``[bcd]*`` 尝试零匹配,如果随后失败,引擎将断定该字符串与正则完全不匹配。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:226
msgid ""
"Another repeating metacharacter is ``+``, which matches one or more times. "
"Pay careful attention to the difference between ``*`` and ``+``; ``*`` "
"matches *zero* or more times, so whatever's being repeated may not be "
"present at all, while ``+`` requires at least *one* occurrence. To use a "
"similar example, ``ca+t`` will match ``'cat'`` (1 ``'a'``), ``'caaat'`` (3 "
"``'a'``\\ s), but won't match ``'ct'``."
msgstr ""
"另一个重复的元字符是 ``+``,它匹配一次或多次。 要特别注意 ``*`` 和 ``+`` 之间的区别;``*`` 匹配 *零次* "
"或更多次,因此重复的任何东西都可能根本不存在,而 ``+`` 至少需要 *一次*。 使用类似的例子,``ca+t`` 将匹配 ``'cat'`` (1 "
"个 ``'a'``),``'caaat'`` (3 个 ``'a'``),但不会匹配 ``'ct'``。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:233
msgid ""
"There are two more repeating qualifiers. The question mark character, "
"``?``, matches either once or zero times; you can think of it as marking "
"something as being optional. For example, ``home-?brew`` matches either "
"``'homebrew'`` or ``'home-brew'``."
msgstr ""
"还有两个重复限定符。 问号字符 ``?`` 匹配一次或零次;你可以把它想象成是可选的。 例如,``home-?brew`` 匹配 "
"``'homebrew'`` 或 ``'home-brew'``。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:238
msgid ""
"The most complicated repeated qualifier is ``{m,n}``, where *m* and *n* are "
"decimal integers. This qualifier means there must be at least *m* "
"repetitions, and at most *n*. For example, ``a/{1,3}b`` will match "
"``'a/b'``, ``'a//b'``, and ``'a///b'``. It won't match ``'ab'``, which has "
"no slashes, or ``'a////b'``, which has four."
msgstr ""
"最复杂的重复限定符是 ``{m,n}``,其中 *m* 和 *n* 是十进制整数。 这个限定符意味着必须至少重复 *m* 次,最多重复 *n* 次。 "
"例如,``a/{1,3}b`` 将匹配 ``'a/b'`` ,``'a//b'`` 和 ``'a///b'`` 。 它不匹配没有斜线的 "
"``'ab'``,或者有四个的 ``'a////b'``。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:244
msgid ""
"You can omit either *m* or *n*; in that case, a reasonable value is assumed "
"for the missing value. Omitting *m* is interpreted as a lower limit of 0, "
"while omitting *n* results in an upper bound of infinity."
msgstr ""
"你可以省略 *m* 或 *n*; 在这种情况下,将假定缺失值的合理值。 省略 *m* 被解释为 0 下限,而省略 *n* 则为无穷大的上限。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:248
msgid ""
"Readers of a reductionist bent may notice that the three other qualifiers "
"can all be expressed using this notation. ``{0,}`` is the same as ``*``, "
"``{1,}`` is equivalent to ``+``, and ``{0,1}`` is the same as ``?``. It's "
"better to use ``*``, ``+``, or ``?`` when you can, simply because they're "
"shorter and easier to read."
msgstr ""
"还原论者的读者可能会注意到其他三个限定符都可以用这种表示法表达。 "
"``{0,}``与``*``相同,``{1,}``相当于``+``,``{0,1}``和``?``相同。 "
"最好使用``*``,``+``或``?``,只要因为它们更短更容易阅读。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:256
msgid "Using Regular Expressions"
msgstr "使用正则表达式"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:258
msgid ""
"Now that we've looked at some simple regular expressions, how do we actually"
" use them in Python? The :mod:`re` module provides an interface to the "
"regular expression engine, allowing you to compile REs into objects and then"
" perform matches with them."
msgstr ""
"现在我们已经看了一些简单的正则表达式,我们如何在 Python 中实际使用它们? :mod:`re` "
"模块提供了正则表达式引擎的接口,允许你将正则编译为对象,然后用它们进行匹配。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:265
msgid "Compiling Regular Expressions"
msgstr "编译正则表达式"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:267
msgid ""
"Regular expressions are compiled into pattern objects, which have methods "
"for various operations such as searching for pattern matches or performing "
"string substitutions. ::"
msgstr "正则表达式被编译成模式对象,模式对象具有各种操作的方法,例如搜索模式匹配或执行字符串替换。::"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:276
msgid ""
":func:`re.compile` also accepts an optional *flags* argument, used to enable"
" various special features and syntax variations. We'll go over the "
"available settings later, but for now a single example will do::"
msgstr ""
":func:`re.compile` 也接受一个可选的 *flags* 参数,用于启用各种特殊功能和语法变体。 "
"我们稍后将介绍可用的设置,但现在只需一个例子 ::"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:282
msgid ""
"The RE is passed to :func:`re.compile` as a string. REs are handled as "
"strings because regular expressions aren't part of the core Python language,"
" and no special syntax was created for expressing them. (There are "
"applications that don't need REs at all, so there's no need to bloat the "
"language specification by including them.) Instead, the :mod:`re` module is "
"simply a C extension module included with Python, just like the "
":mod:`socket` or :mod:`zlib` modules."
msgstr ""
"正则作为字符串传递给 :func:`re.compile` 。 "
"正则被处理为字符串,因为正则表达式不是核心Python语言的一部分,并且没有创建用于表达它们的特殊语法。 "
"(有些应用程序根本不需要正则,因此不需要通过包含它们来扩展语言规范。)相反,:mod:`re` 模块只是Python附带的C扩展模块,就类似于 "
":mod:`socket` 或 :mod:`zlib` 模块。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:289
msgid ""
"Putting REs in strings keeps the Python language simpler, but has one "
"disadvantage which is the topic of the next section."
msgstr "将正则放在字符串中可以使 Python 语言更简单,但有一个缺点是下一节的主题。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:296
msgid "The Backslash Plague"
msgstr "反斜杠灾难"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:298
msgid ""
"As stated earlier, regular expressions use the backslash character "
"(``'\\'``) to indicate special forms or to allow special characters to be "
"used without invoking their special meaning. This conflicts with Python's "
"usage of the same character for the same purpose in string literals."
msgstr ""
"如前所述,正则表达式使用反斜杠字符 (``'\\'``) 来表示特殊形式或允许使用特殊字符而不调用它们的特殊含义。 这与 Python "
"在字符串文字中用于相同目的的相同字符的使用相冲突。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:303
msgid ""
"Let's say you want to write a RE that matches the string ``\\section``, "
"which might be found in a LaTeX file. To figure out what to write in the "
"program code, start with the desired string to be matched. Next, you must "
"escape any backslashes and other metacharacters by preceding them with a "
"backslash, resulting in the string ``\\\\section``. The resulting string "
"that must be passed to :func:`re.compile` must be ``\\\\section``. However,"
" to express this as a Python string literal, both backslashes must be "
"escaped *again*."
msgstr ""
"假设你想要编写一个与字符串 ``\\section`` 相匹配的正则,它可以在 LaTeX 文件中找到。 "
"要找出在程序代码中写入的内容,请从要匹配的字符串开始。 接下来,您必须通过在反斜杠前面添加反斜杠和其他元字符,从而产生字符串 "
"``\\\\section``。 必须传递给 :func:`re.compile` 的结果字符串必须是 ``\\\\section``。 "
"但是,要将其表示为 Python 字符串文字,必须 *再次* 转义两个反斜杠。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:312
msgid "Characters"
msgstr "字符"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:312
msgid "Stage"
msgstr "阶段"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:314
msgid "``\\section``"
msgstr "``\\section``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:314
msgid "Text string to be matched"
msgstr "被匹配的字符串"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:316
msgid "``\\\\section``"
msgstr "``\\\\section``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:316
msgid "Escaped backslash for :func:`re.compile`"
msgstr "为 :func:`re.compile` 转义的反斜杠"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:318
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:345
msgid "``\"\\\\\\\\section\"``"
msgstr "``\"\\\\\\\\section\"``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:318
msgid "Escaped backslashes for a string literal"
msgstr "为字符串字面转义的反斜杠"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:321
msgid ""
"In short, to match a literal backslash, one has to write ``'\\\\\\\\'`` as "
"the RE string, because the regular expression must be ``\\\\``, and each "
"backslash must be expressed as ``\\\\`` inside a regular Python string "
"literal. In REs that feature backslashes repeatedly, this leads to lots of "
"repeated backslashes and makes the resulting strings difficult to "
"understand."
msgstr ""
"简而言之,要匹配文字反斜杠,必须将 ``'\\\\\\\\'`` 写为正则字符串,因为正则表达式必须是 ``\\\\``,并且每个反斜杠必须表示为 "
"``\\\\`` 在常规Python字符串字面中。 在反复使用反斜杠的正则中,这会导致大量重复的反斜杠,并使得生成的字符串难以理解。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:327
msgid ""
"The solution is to use Python's raw string notation for regular expressions;"
" backslashes are not handled in any special way in a string literal prefixed"
" with ``'r'``, so ``r\"\\n\"`` is a two-character string containing ``'\\'``"
" and ``'n'``, while ``\"\\n\"`` is a one-character string containing a "
"newline. Regular expressions will often be written in Python code using this"
" raw string notation."
msgstr ""
"解决方案是使用 Python 的原始字符串表示法来表示正则表达式;反斜杠不以任何特殊的方式处理前缀为 ``'r'`` 的字符串字面,因此 "
"``r\"\\n\"`` 是一个包含 ``'\\'`` 和 ``'n'`` 的双字符字符串,而 ``\"\\n\"`` 是一个包含换行符的单字符字符串。"
" 正则表达式通常使用这种原始字符串表示法用 Python 代码编写。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:333
msgid ""
"In addition, special escape sequences that are valid in regular expressions,"
" but not valid as Python string literals, now result in a "
":exc:`DeprecationWarning` and will eventually become a :exc:`SyntaxError`, "
"which means the sequences will be invalid if raw string notation or escaping"
" the backslashes isn't used."
msgstr ""
"此外,在正则表达式中有效但在 Python 字符串文字中无效的特殊转义序列现在导致 :exc:`DeprecationWarning` 并最终变为 "
":exc:`SyntaxError`。 这意味着如果未使用原始字符串表示法或转义反斜杠,序列将无效。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:341
msgid "Regular String"
msgstr "常规字符串"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:341
msgid "Raw string"
msgstr "原始字符串"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:343
msgid "``\"ab*\"``"
msgstr "``\"ab*\"``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:343
msgid "``r\"ab*\"``"
msgstr "``r\"ab*\"``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:345
msgid "``r\"\\\\section\"``"
msgstr "``r\"\\\\section\"``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:347
msgid "``\"\\\\w+\\\\s+\\\\1\"``"
msgstr "``\"\\\\w+\\\\s+\\\\1\"``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:347
msgid "``r\"\\w+\\s+\\1\"``"
msgstr "``r\"\\w+\\s+\\1\"``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:352
msgid "Performing Matches"
msgstr "应用匹配"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:354
msgid ""
"Once you have an object representing a compiled regular expression, what do "
"you do with it? Pattern objects have several methods and attributes. Only "
"the most significant ones will be covered here; consult the :mod:`re` docs "
"for a complete listing."
msgstr ""
"一旦你有一个表示编译正则表达式的对象,你用它做什么? 模式对象有几种方法和属性。 这里只介绍最重要的内容;请参阅 :mod:`re` 文档获取完整列表。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:360
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:418
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:1057
msgid "Method/Attribute"
msgstr "方法 / 属性"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:360
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:418
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:1057
msgid "Purpose"
msgstr "目的"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:362
msgid "``match()``"
msgstr "``match()``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:362
msgid "Determine if the RE matches at the beginning of the string."
msgstr "确定正则是否从字符串的开头匹配。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:365
msgid "``search()``"
msgstr "``search()``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:365
msgid "Scan through a string, looking for any location where this RE matches."
msgstr "扫描字符串,查找此正则匹配的任何位置。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:368
msgid "``findall()``"
msgstr "``findall()``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:368
msgid "Find all substrings where the RE matches, and returns them as a list."
msgstr "找到正则匹配的所有子字符串,并将它们作为列表返回。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:371
msgid "``finditer()``"
msgstr "``finditer()``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:371
msgid ""
"Find all substrings where the RE matches, and returns them as an "
":term:`iterator`."
msgstr "找到正则匹配的所有子字符串,并将它们返回为一个 :term:`iterator`。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:375
msgid ""
":meth:`~re.Pattern.match` and :meth:`~re.Pattern.search` return ``None`` if "
"no match can be found. If they're successful, a :ref:`match object <match-"
"objects>` instance is returned, containing information about the match: "
"where it starts and ends, the substring it matched, and more."
msgstr ""
"如果没有找到匹配, :meth:`~re.Pattern.match` 和 :meth:`~re.Pattern.search` 返回 ``None``"
" 。如果它们成功, 一个 :ref:`匹配对象 <match-objects>` 实例将被返回,包含匹配相关的信息:起始和终结位置、匹配的子串以及其它。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:380
msgid ""
"You can learn about this by interactively experimenting with the :mod:`re` "
"module. If you have :mod:`tkinter` available, you may also want to look at "
":source:`Tools/demo/redemo.py`, a demonstration program included with the "
"Python distribution. It allows you to enter REs and strings, and displays "
"whether the RE matches or fails. :file:`redemo.py` can be quite useful when "
"trying to debug a complicated RE."
msgstr ""
"你可以通过交互式实验 :mod:`re` 模块来了解这一点。 如果你有 :mod:`tkinter`,你可能还想查看 "
":source:`Tools/demo/redemo.py`,这是 Python 发行附带的演示程序。 "
"它允许你输入正则和字符串,并显示RE是匹配还是失败。 :file:`redemo.py` 在尝试调试复杂的正则时非常有用。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:387
msgid ""
"This HOWTO uses the standard Python interpreter for its examples. First, run"
" the Python interpreter, import the :mod:`re` module, and compile a RE::"
msgstr ""
"本 HOWTO 使用标准 Python 解释器作为示例。 首先,运行 Python 解释器,导入 :mod:`re` 模块,然后编译一个正则 ::"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:395
msgid ""
"Now, you can try matching various strings against the RE ``[a-z]+``. An "
"empty string shouldn't match at all, since ``+`` means 'one or more "
"repetitions'. :meth:`~re.Pattern.match` should return ``None`` in this case,"
" which will cause the interpreter to print no output. You can explicitly "
"print the result of :meth:`!match` to make this clear. ::"
msgstr ""
"现在,你可以尝试匹配正则 ``[a-z]+`` 的各种字符串。 空字符串根本不匹配,因为 ``+`` 表示“一次或多次重复”。 "
":meth:`~re.Pattern.match` 在这种情况下应返回 ``None``,这将导致解释器不打印输出。 你可以显式打印 "
":meth:`!match` 的结果,使其清晰。::"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:405
msgid ""
"Now, let's try it on a string that it should match, such as ``tempo``. In "
"this case, :meth:`~re.Pattern.match` will return a :ref:`match object "
"<match-objects>`, so you should store the result in a variable for later "
"use. ::"
msgstr ""
"现在,让我们尝试一下它应该匹配的字符串,例如 ``tempo``。在这个例子中 :meth:`~re.Pattern.match` 将返回一个 "
":ref:`匹配对象 <match-objects>`,因此你应该将结果储存到一个变量中以供稍后使用。 ::"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:413
msgid ""
"Now you can query the :ref:`match object <match-objects>` for information "
"about the matching string. Match object instances also have several methods"
" and attributes; the most important ones are:"
msgstr ""
"现在你可以检查 :ref:`匹配对象 <match-objects>` 以获取有关匹配字符串的信息。 匹配对象实例也有几个方法和属性;最重要的是:"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:420
msgid "``group()``"
msgstr "``group()``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:420
msgid "Return the string matched by the RE"
msgstr "返回正则匹配的字符串"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:422
msgid "``start()``"
msgstr "``start()``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:422
msgid "Return the starting position of the match"
msgstr "返回匹配的开始位置"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:424
msgid "``end()``"
msgstr "``end()``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:424
msgid "Return the ending position of the match"
msgstr "返回匹配的结束位置"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:426
msgid "``span()``"
msgstr "``span()``"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:426
msgid "Return a tuple containing the (start, end) positions of the match"
msgstr "返回包含匹配 (start, end) 位置的元组"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:430
msgid "Trying these methods will soon clarify their meaning::"
msgstr "尝试这些方法很快就会清楚它们的含义::"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:439
msgid ""
":meth:`~re.Match.group` returns the substring that was matched by the RE. "
":meth:`~re.Match.start` and :meth:`~re.Match.end` return the starting and "
"ending index of the match. :meth:`~re.Match.span` returns both start and end"
" indexes in a single tuple. Since the :meth:`~re.Pattern.match` method only"
" checks if the RE matches at the start of a string, :meth:`!start` will "
"always be zero. However, the :meth:`~re.Pattern.search` method of patterns "
"scans through the string, so the match may not start at zero in that case. "
"::"
msgstr ""
":meth:`~re.Match.group` 返回正则匹配的子字符串。 :meth:`~re.Match.start` 和 "
":meth:`~re.Match.end` 返回匹配的起始和结束索引。 :meth:`~re.Match.span` 在单个元组中返回开始和结束索引。 "
"由于 :meth:`~re.Pattern.match` 方法只检查正则是否在字符串的开头匹配,所以 :meth:`!start` 将始终为零。 "
"但是,模式的 :meth:`~re.Pattern.search` 方法会扫描字符串,因此在这种情况下匹配可能不会从零开始。::"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:456
msgid ""
"In actual programs, the most common style is to store the :ref:`match object"
" <match-objects>` in a variable, and then check if it was ``None``. This "
"usually looks like::"
msgstr ""
"在实际程序中,最常见的样式是在变量中存储 :ref:`匹配对象 <match-objects>`,然后检查它是否为 ``None``。 "
"这通常看起来像::"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:467
msgid ""
"Two pattern methods return all of the matches for a pattern. "
":meth:`~re.Pattern.findall` returns a list of matching strings::"
msgstr "两种模式方法返回模式的所有匹配项。 :meth:`~re.Pattern.findall` 返回匹配字符串的列表::"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:474
msgid ""
"The ``r`` prefix, making the literal a raw string literal, is needed in this"
" example because escape sequences in a normal \"cooked\" string literal that"
" are not recognized by Python, as opposed to regular expressions, now result"
" in a :exc:`DeprecationWarning` and will eventually become a "
":exc:`SyntaxError`. See :ref:`the-backslash-plague`."
msgstr ""
"在这个例子中需要 ``r`` 前缀,使字面为原始字符串字面,因为普通的“加工”字符串字面中的转义序列不能被 Python 识别为正则表达式,导致 "
":exc:`DeprecationWarning` 并最终产生 :exc:`SyntaxError`。 请参阅 :ref:`the-backslash-"
"plague`。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:480
msgid ""
":meth:`~re.Pattern.findall` has to create the entire list before it can be "
"returned as the result. The :meth:`~re.Pattern.finditer` method returns a "
"sequence of :ref:`match object <match-objects>` instances as an "
":term:`iterator`::"
msgstr ""
":meth:`~re.Pattern.findall` 必须先创建整个列表才能返回结果。 :meth:`~re.Pattern.finditer` "
"方法将一个 :ref:`匹配对象 <match-objects>` 的序列返回为一个 :term:`iterator` ::"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:496
msgid "Module-Level Functions"
msgstr "模块级别函数"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:498
msgid ""
"You don't have to create a pattern object and call its methods; the "
":mod:`re` module also provides top-level functions called :func:`~re.match`,"
" :func:`~re.search`, :func:`~re.findall`, :func:`~re.sub`, and so forth. "
"These functions take the same arguments as the corresponding pattern method "
"with the RE string added as the first argument, and still return either "
"``None`` or a :ref:`match object <match-objects>` instance. ::"
msgstr ""
"你不必创建模式对象并调用其方法;:mod:`re` 模块还提供了顶级函数 "
":func:`~re.match`,:func:`~re.search`,:func:`~re.findall`,:func:`~re.sub` 等等。"
" 这些函数采用与相应模式方法相同的参数,并将正则字符串作为第一个参数添加,并仍然返回 ``None`` 或 :ref:`匹配对象 <match-"
"objects>` 实例。::"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:510
msgid ""
"Under the hood, these functions simply create a pattern object for you and "
"call the appropriate method on it. They also store the compiled object in a"
" cache, so future calls using the same RE won't need to parse the pattern "
"again and again."
msgstr ""
"本质上,这些函数只是为你创建一个模式对象,并在其上调用适当的方法。 它们还将编译对象存储在缓存中,因此使用相同的未来调用将不需要一次又一次地解析该模式。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:515
msgid ""
"Should you use these module-level functions, or should you get the pattern "
"and call its methods yourself? If you're accessing a regex within a loop, "
"pre-compiling it will save a few function calls. Outside of loops, there's "
"not much difference thanks to the internal cache."
msgstr ""
"你是否应该使用这些模块级函数,还是应该自己获取模式并调用其方法? 如果你正在循环中访问正则表达式,预编译它将节省一些函数调用。 "
"在循环之外,由于有内部缓存,没有太大区别。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:523
msgid "Compilation Flags"
msgstr "编译标志"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:525
msgid ""
"Compilation flags let you modify some aspects of how regular expressions "
"work. Flags are available in the :mod:`re` module under two names, a long "
"name such as :const:`IGNORECASE` and a short, one-letter form such as "
":const:`I`. (If you're familiar with Perl's pattern modifiers, the one-"
"letter forms use the same letters; the short form of :const:`re.VERBOSE` is "
":const:`re.X`, for example.) Multiple flags can be specified by bitwise OR-"
"ing them; ``re.I | re.M`` sets both the :const:`I` and :const:`M` flags, for"
" example."
msgstr ""
"编译标志允许你修改正则表达式的工作方式。 标志在 :mod:`re` 模块中有两个名称,长名称如 :const:`IGNORECASE` "
"和一个简短的单字母形式,例如 :const:`I`。 (如果你熟悉 Perl 的模式修饰符,则单字母形式使用和其相同的字母;例如, "
":const:`re.VERBOSE` 的缩写形式为 :const:`re.X`。)多个标志可以 通过按位或运算来指定它们;例如,``re.I | "
"re.M`` 设置 :const:`I` 和 :const:`M` 标志。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:533
msgid ""
"Here's a table of the available flags, followed by a more detailed "
"explanation of each one."
msgstr "这是一个可用标志表,以及每个标志的更详细说明。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:537
msgid "Flag"
msgstr "标志"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:537
msgid "Meaning"
msgstr "含义"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:539
msgid ":const:`ASCII`, :const:`A`"
msgstr ":const:`ASCII`, :const:`A`"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:539
msgid ""
"Makes several escapes like ``\\w``, ``\\b``, ``\\s`` and ``\\d`` match only "
"on ASCII characters with the respective property."
msgstr "使几个转义如 ``\\w``、``\\b``、``\\s`` 和 ``\\d`` 匹配仅与具有相应特征属性的 ASCII 字符匹配。"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:543
msgid ":const:`DOTALL`, :const:`S`"
msgstr ":const:`DOTALL`, :const:`S`"
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/howto/regex.rst:543
msgid "Make ``.`` match any character, including newlines."
msgstr "使 ``.`` 匹配任何字符,包括换行符。"