@@ -1573,16 +1573,17 @@ say $/<ipv4-octet>; # OUTPUT: [「127」 「0」 「0」 「1」]
1573
1573
1574
1574
= head1 Adverbs
1575
1575
1576
- Adverbs modify how regexes work and provide convenient shortcuts for
1577
- certain kinds of recurring tasks.
1576
+ Adverbs, which modify how regexes work and provide convenient shortcuts for
1577
+ certain kinds of recurring tasks, are combinations of one or more letters
1578
+ preceded by a colon C < : > .
1578
1579
1579
- There are two kinds of adverbs: regex adverbs apply at the point where a
1580
- regex is defined and matching adverbs apply at the point that a regex
1580
+ There are two kinds of adverbs: I < regex > adverbs apply at the point where a
1581
+ regex is defined, and I < matching > adverbs apply at the point that a regex
1581
1582
matches against a string.
1582
1583
1583
1584
This distinction often blurs, because matching and declaration are often
1584
- textually close but using the method form of matching makes the distinction
1585
- clear.
1585
+ textually close but using the method form of matching, that is, C < .match > , makes
1586
+ the distinction clear.
1586
1587
1587
1588
C < 'abc' ~~ /../ > is roughly equivalent to C < 'abc'.match(/../) > , or even more
1588
1589
clearly written in separate lines:
@@ -1592,8 +1593,8 @@ clearly written in separate lines:
1592
1593
say "'abc' has at least two characters";
1593
1594
}
1594
1595
1595
- Regex adverbs like C < :i > go into the definition line and matching adverbs
1596
- like C < :overlap > are appended to the match call:
1596
+ Regex adverbs like C < :i > go into the definition line and matching adverbs like
1597
+ C < :overlap > (which can be abbreviated to C < :ov > ) are appended to the match call:
1597
1598
1598
1599
my $regex = /:i . a/;
1599
1600
for 'baA'.match($regex, :overlap) -> $m {
@@ -1603,7 +1604,7 @@ like C<:overlap> are appended to the match call:
1603
1604
1604
1605
= head2 X < Regex adverbs|regex adverb,:ignorecase;regex adverb,:i >
1605
1606
1606
- Adverbs that appear at the time of a regex declaration are part of the
1607
+ The adverbs that appear at the time of a regex declaration are part of the
1607
1608
actual regex and influence how the Perl 6 compiler translates the regex into
1608
1609
binary code.
1609
1610
@@ -1612,15 +1613,14 @@ the distinction between upper case, lower case and title case letters.
1612
1613
1613
1614
So C < 'a' ~~ /A/ > is false, but C < 'a' ~~ /:i A/ > is a successful match.
1614
1615
1615
- Regex adverbs can come before or inside a regex declaration and only affect
1616
- the part of the regex that comes afterwards, lexically.
1617
- Note that regex adverbs appearing before the regex must appear after
1618
- something that introduces the regex to the parser, like 'rx' or 'm' or a bare '/'.
1619
- This is NOT valid:
1616
+ Regex adverbs can come before or inside a regex declaration and only affect the
1617
+ part of the regex that comes afterwards, lexically. Note that regex adverbs
1618
+ appearing before the regex must appear after something that introduces the regex
1619
+ to the parser, like 'rx' or 'm' or a bare '/'. This is NOT valid:
1620
1620
1621
- = begin code :skip-test
1622
- my $rx1 = :i/a/; # adverb is before the regex is recognized => exception
1623
- = end code
1621
+ = begin code :skip-test
1622
+ my $rx1 = :i/a/; # adverb is before the regex is recognized => exception
1623
+ = end code
1624
1624
1625
1625
but these are valid:
1626
1626
@@ -1643,6 +1643,13 @@ Square brackets and parentheses limit the scope of an adverb:
1643
1643
/ (:i a b) c /; # matches 'ABc' but not 'ABC'
1644
1644
/ [:i a b] c /; # matches 'ABc' but not 'ABC'
1645
1645
1646
+ When two adverbs are used together, they keep their colon at the front
1647
+
1648
+ "þor is Þor" ~~ m:g:i/þ/;# OUTPUT: «(「þ」 「Þ」)»
1649
+
1650
+ That implies that when there are two vowels together after a C < : > , they
1651
+ correspond to the same adverb, as in C < :ov > or C < :P5 > .
1652
+
1646
1653
= head3 X < Ignoremark|regex adverb,:ignoremark;regex adverb,:m >
1647
1654
1648
1655
The C < :ignoremark > or C < :m > adverb instructs the regex engine to only
0 commit comments