Skip to content

Commit 9893517

Browse files
authored
Document Regex Interpolation
I think it's worthy to be documented, because people will looking for a way to using patten given at the runtime. But I'm not sure if this's the only way to interpolate patten(string) into regex.
1 parent 0333bf5 commit 9893517

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

doc/Language/regexes.pod6

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,18 @@ list of predefined subrules is listed in
12551255
L<S05-regex|https://design.perl6.org/S05.html#Predefined_Subrules> of design
12561256
documents.
12571257
1258+
=head1 X«Regex Interpolation|Regex Interpolation; <$patten>»
1259+
1260+
If you want to build a regex using pattern given at the runtime, regex
1261+
interpolation is what you looking for.
1262+
1263+
sub runtime-regex(Str $patten --> Regex) { /<$patten>/ }
1264+
1265+
my $regex = runtime-regex(get); # INPUT : «\d+␤»
1266+
my $text = get; # INPUT : «42␤»
1267+
1268+
say $text ~~ $regex; # OUTPUT : «「42」␤»
1269+
12581270
=head1 Adverbs
12591271
12601272
Adverbs modify how regexes work and provide convenient shortcuts for

0 commit comments

Comments
 (0)