Regex to match 1 or less occurrence of string?

You might want to have a look at a regex tutorial.

Optional parts of a regex are indicated with a question mark:

Jump over this bridge( FOOL)?

In case you want to match any string that includes FOOL less than twice, things get a bit more complicated. Then you would be best off using the more advanced concept of a negative lookahead:

^(?!(.*FOOL){2})

This turns the logic on its head and asserts that the string doesn’t contain 2 (or more) instances of FOOL.

Leave a Comment

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