regex - perl negative lookahead for not matching a word -
i found regex not match word question regular look match string not containing word? .
u(?!i)
match word u not followed i. reply says checks if each character not followed hede. shouldn't regex /^(.(?!hede))*$/
. works words containing hede not starting it. why utilize /^((?!hede).)*$/
. whats difference between position of dot. used re=debug
couldn't still meaning
(?!hede)
means look ahead see if there not: hede
. create sense if there other character followed hede
hence .
after (?!hede)
valid regex.
regex explanation of ^((?!hede).)*$
^ origin of string ( grouping , capture \1 (0 or more times): (?! ahead see if there not: hede 'hede' ) end of look-ahead . character except \n )* end of \1 $ before optional \n, , end of string
use (?<!
look behind
pattern explanation of ^(.(?<!hede))*$
^ origin of string ( grouping , capture \1 (0 or more times): . character except \n (?<! behind see if there not: hede 'hede' ) end of look-behind )* end of \1 $ before optional \n, , end of string
it's improve explained under lookahead , lookbehind zero-length assertions
they not consume characters in string, assert whether match possible or not
regex perl
No comments:
Post a Comment