regex - pcre regexp - weird Lookbehind assertion is not fixed width -


i new regexps , trying understand regexp:

(?<!mix\s|mixe[rds]\s|mixing\s)with(?:out)? 

in opinions search with or without if not followed following words:

  • mix
  • mixer/mixed/mixes
  • mixing

so trying re-write it as:

(?<!mix(?:e[rnds]|ing)?\s)with(?:out)? 

but following error:

  • lookbehind assertion not fixed width

i understand how lookbehind works (it goes fixed width , tries match) aren't 2 regexp inside lookbehind same regexp?

(i found info here, still not clear why in case not work) what's technical reason "lookbehind assertion must fixed length" in regex?

it doesn't work in case because sub-pattern contains quantifier ?. when quantifier found regex engine decides sub-pattern has no more fixed length (that true).

even if 2 sub-patterns equivalent (but regex engine ignore that), fact there quantifier makes pattern analysis fail.

on other hand pcre accepts several fixed length sub-patterns separated pipe.

a classical workaround avoid problem pcre consists use \k feature discard characters found match result:

(?<!mix)(?:e[rnds]|ing)?\s\kwith(?:out)? 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -