File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -1324,6 +1324,9 @@ a semantic evaluation of the match before the regular expression continues. In o
1324
1324
to check in aboolean context a part of a regular expression and therefore invalidate the whole match (or allow it
1325
1325
to continue) even if the match succeed from a syntactic point of view.
1326
1326
1327
+ In particular the C « <?{}> » operator requires a C < True > value in order to allow the regular expression to match, while its
1328
+ negate form C « <!{}> » requires a C < False > value.
1329
+
1327
1330
In order to demonstrate the above operator, please consider the following example that involves
1328
1331
a simple IPv4 address matching:
1329
1332
@@ -1347,6 +1350,16 @@ $localhost ~~ / ^ <ipv4-octet> ** 4 % "." $ /;
1347
1350
say $/<ipv4-octet>; # OUTPUT: Nil
1348
1351
= end code
1349
1352
1353
+ From the above examples, it should be clear that it is possible to improve the semantic check, for instance
1354
+ ensuring that each I < octet > is really a valid IPv4 octect:
1355
+
1356
+ = begin code
1357
+ my $localhost = '127.0.0.1';
1358
+ my regex ipv4-octet { \d ** 1..3 <?{ $/.Int <= 255 && $/.Int >= 0 }> }
1359
+ $localhost ~~ / ^ <ipv4-octet> ** 4 % "." $ /;
1360
+ say $/<ipv4-octet>; # OUTPUT: [「127」 「0」 「0」 「1」]
1361
+ = end code
1362
+
1350
1363
1351
1364
= head1 Adverbs
1352
1365
You can’t perform that action at this time.
0 commit comments