0

I am trying to figure out how to write a regex expression that returns the word "AI" without returning words that contain "ai".

My guess is that I would need to use operators that return "ai" only if there is whitespace one character to the left of "ai" and whitespace one character to the right of "ai".

but allows for punctuation on either end.

The goal is to return a search result like:

"AI, the future of computing"

or

"Has AI finally arrived?"

as opposed to

"He said what?" (Notice ai is within the word "said".)

2 Answers2

2

Use \b that denotes a word boundary. E.g. \bAI\b.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
0

You can also use \b(AI)\b for this instance.

Base64.ai
  • 1
  • 3