regex - How to exclude text between boundaries? -
regex - How to exclude text between boundaries? -
i'm trying understand why illustration regex not work way i'd to:
test-text: filename: test myfile 123 .txt pattern: (?<=filename:.*?myfile)(.*?)(?=.txt) expected result: 123
i know lookahead/behind not ideal here, it's learning purpose trying understand.
so why .*?myfile
not work? if remove it, pattern matches test myfile 123
. want filename:
, exclude myfile
, , take after , bewteen lastly .txt
statement. missing here?
due complexities of regex matching, variable-length lookbehind pattern not supported. should error message effect. limitation of perl's regex engine.
there similar feature allows this: \k
discards left final match. pattern work expect to:
/filename:.*?myfile\k(.*?)(?=.txt)/
it not same true lookbehind, however, in doesn't allow overlapping matches.
incidentally, 3rd similar question have posted. based on info have given, right reply still "don't utilize look-arounds this". if there reason want utilize them, should explain can give improve help.
regex
Comments
Post a Comment