Newbie searching for regex

41 views Asked by At

I am looking for a regex to find as well "right" and "all right" in a text.

I tried:

\ball\W+\w+ight\b

This only gives as a result "all right", not both "right" and "all right".

Same problem to find both it and its, it's and it is.

2

There are 2 answers

11
Tobias Tengler On BEST ANSWER

This should work:

\b(?:all\s)?right\b

This matches right and an optional(?) all + whitespace(\s) in front of it, if present.

The \b anchors are there to make sure that there is a word boundary before all or right and after right.

Additionally the ?: is here to not capture the all\s group.

Example

EDIT

it is / it's:

\bit(?:'s|\sis)\b

it / its

\bit(?:s)?\b
1
Maya Davis On

Try this \ball\W+\w+ight\b|\w+ight\b This is a good tool for working with some cases of regex http://rubular.com/