perl regex to match any `word character' except Q -
i need regex match character or word except q.
i tried using expression
/\b((?!(q)).+?)\b/
but not working!
are trying forbid word "q", or words include "q"?
forbidding words include "q"
use double negation: "a character that's (\w , not-q)" "a character that's not (not-\w or q)".
[^\wq] => /\b([^\wq]+)\b/
you use
(?!q)\w => /\b((?:(?!q)\w)+)\b/
i think first 1 faster.
forbidding word "q"
/\b(q\w+|[^\wq]\w*)\b/
or
/\b(?!q\b)(\w+)\b/
Comments
Post a Comment