Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex only matches it and its, but not it's

I'm trying to get a regex to match the words it, its, and it's.

I'm using \b to match words, but it seems like it is only matching characters. How can I get it to match anything, but whitespace?

Here is the regex so far: \b(it|it's|its)\b. How can I get it to match exactly the words it, it's, and its?

like image 841
wordSmith Avatar asked Jun 25 '14 02:06

wordSmith


1 Answers

This one will work:

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

Your pattern doesn't work with it's because in the alternation the item it (that is tested first) succeeds before it's that is not tested at all. You can write \b(it's|it|its)\b too.

like image 190
Casimir et Hippolyte Avatar answered Oct 18 '22 12:10

Casimir et Hippolyte