regex word boundary excluding the hyphen

You can use a lookahead for this, the shortest would be to use a negative lookahead:

type ([a-z])(?![\w-])

(?![\w-]) would mean “fail the match if the next character is in \w or is a -“.

Here is an option that uses a normal lookahead:

type ([a-z])(?=[^\w-]|$)

You can read (?=[^\w-]|$) as “only match if the next character is not in the character class [\w-], or this is the end of the string”.

See it working: http://www.rubular.com/r/NHYhv72znm

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)