diff options
author | Karl Williamson <khw@cpan.org> | 2021-01-14 07:52:26 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2021-01-20 06:51:50 -0700 |
commit | 1b2f32d508340483aa270e0caf653ba0454345d1 (patch) | |
tree | 154177a878f233a5023ff8bbb06271fed6526c38 /pod/perlrebackslash.pod | |
parent | a44b2be795f4c5f94384c6f6010860588e144b3c (diff) | |
download | perl-1b2f32d508340483aa270e0caf653ba0454345d1.tar.gz |
Allow blanks within and adjacent to {...} constructs
This was the consensus in
http://nntp.perl.org/group/perl.perl5.porters/258489
Diffstat (limited to 'pod/perlrebackslash.pod')
-rw-r--r-- | pod/perlrebackslash.pod | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/pod/perlrebackslash.pod b/pod/perlrebackslash.pod index 9500bef527..d6539ad99d 100644 --- a/pod/perlrebackslash.pod +++ b/pod/perlrebackslash.pod @@ -186,6 +186,10 @@ digits. Thus C<\N{U+0041}> means C<LATIN CAPITAL LETTER A>, and you will rarely see it written without the two leading zeros. C<\N{U+0041}> means "A" even on EBCDIC machines (where the ordinal value of "A" is not 0x41). +Blanks may freely be inserted adjacent to but within the braces +enclosing the name or code point. So S<C<\N{ U+0041 }>> is perfectly +legal. + It is even possible to give your own names to characters and character sequences by using the L<charnames> module. These custom names are lexically scoped, and so a given code point may have different names @@ -260,6 +264,9 @@ Mnemonic: I<0>ctal or I<o>ctal. $str =~ /P\053/; # No match, "\053" is "+" and taken literally. /\o{23073}/ # Black foreground, white background smiling face. /\o{4801234567}/ # Raises a warning, and yields chr(4). + /\o{ 400}/ # LATIN CAPITAL LETTER A WITH MACRON + /\o{ 400 }/ # Same. These show blanks are allowed adjacent to + # the braces =head4 Disambiguation rules between old-style octal escapes and backreferences @@ -326,6 +333,8 @@ Mnemonic: heI<x>adecimal. # the Unicode character 2602 is an umbrella. /\x{263B}/ # Black smiling face. /\x{263b}/ # Same, the hex digits A - F are case insensitive. + /\x{ 263b }/ # Same, showing optional blanks adjacent to the + # braces =head2 Modifiers @@ -441,6 +450,7 @@ Mnemonic: I<g>roup. /(\w+) \g1/; # Finds a duplicated word, (e.g. "cat cat"). /(\w+) \1/; # Same thing; written old-style. /(\w+) \g{1}/; # Same, using the safer braced notation + /(\w+) \g{ 1 }/;# Same, showing optional blanks adjacent to the braces /(.)(.)\g2\g1/; # Match a four letter palindrome (e.g. "ABBA"). @@ -461,6 +471,7 @@ even if the larger pattern also contains capture groups. (B) # Group 3 \g{-1} # Refers to group 3 (B) \g{-3} # Refers to group 1 (A) + \g{ -3 } # Same, showing optional blanks adjacent to the braces ) /x; # Matches "ABBA". @@ -483,6 +494,11 @@ hyphen. /(?<word>\w+) \g{word}/ # Finds duplicated word, (e.g. "cat cat") /(?<word>\w+) \k{word}/ # Same. + /(?<word>\w+) \g{ word }/ # Same, showing optional blanks adjacent to + # the braces + /(?<word>\w+) \k{ word }/ # Same. + /(?<word>\w+) \k<word>/ # Same. There are no braces, so no blanks + # are permitted /(?<letter1>.)(?<letter2>.)\g{letter2}\g{letter1}/ # Match a four letter palindrome (e.g. # "ABBA") |