File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -904,6 +904,37 @@ abracadabra
904
904
abra
905
905
= end code
906
906
907
+ = head1 Look-around assertions
908
+
909
+ = head2 Lookahead assertions
910
+
911
+ = head2 Lookbehind assertions
912
+
913
+ To check that a pattern appears before another pattern, one can use a
914
+ lookbehind assertion via the C < after > assertion. This has the form:
915
+
916
+ <?after pattern>
917
+
918
+ Thus, to search for the string C < bar > which is immediately preceded by the
919
+ string C < foo > , one could use the following regexp:
920
+
921
+ rx{ <?after foo> bar }
922
+
923
+ which one could use like so:
924
+
925
+ say "foobar" ~~ rx{ <?after foo> bar }; #-> bar
926
+
927
+ However, if you want to search for a pattern which is B < not > immediately
928
+ preceded by some pattern, then you need to use a negative lookbehind
929
+ assertion, this has the form:
930
+
931
+ <?!after pattern>
932
+
933
+ Hence all occurrences of C < bar > which I < do not > have C < foo > before them
934
+ would be matched by
935
+
936
+ rx{ <?!after foo> bar }
937
+
907
938
= head1 Best practices and gotchas
908
939
909
940
Regexes and L < grammars|/language/grammars > are a whole programming paradigm
You can’t perform that action at this time.
0 commit comments