Search code examples
regexgoogle-analyticsregex-lookaroundslookbehind

regex for anything after expression is optional but cannot contain specific characters (what am I doing wrong)?


Here is what I have so far:

./((phraseone|second-phrase|third|fourth)\s*?[^(a-zA-Z\w\d\-\_\.)+])

Okay... What I'm attempting to do:

find any of the for words , which are preceeded by a slash. (hence the "./" ) Then find any of the four phrases what follows those phrases should - NOT be a letter upper or lower case - NOT be a number - NOT be a word (is that redundant?) - NO "-" "_" or "." allowed to follow the phrase

EX: FOUND would = true on

/phraseone?hello=yes
/phraseone
/phraseone&mydog=skip

BUT FOUND would = false on

/phraseonemore
/phraseone-more
etc

Thank you in advance

PS is

./

the proper way to search for a phase and it MUST HAVE the slash preceding one of the four phrases?


Solution

  • You can use negative lookahead like this:

    ./(phraseone|second-phrase|third|fourth)(?![-\w.])
    

    PS: \w is equivalent of [a-zA-Z0-9_]