diracdeltafunk
diracdeltafunk

Reputation: 1194

How would I make this regex?

I want to match the "e" in these strings:

e

e-x-ex

e-x

e-ex

However, I do not want to match the "ex" or dashes in any of them.

What I want in the regex is that it must match only the e in all of the above strings but not these:

x

x-ex

ex

This is probably really easy, but I am not that accomplished at regex making.

I tried e[^x] but that didn't match the string "e" and matched "e-" in "e-x-ex"," "e-x", and "e-ex".

Upvotes: 1

Views: 27

Answers (1)

Cylian
Cylian

Reputation: 11182

Try this

(?i)\be\b

Explanation

"
(?i)    # Match the remainder of the regex with the options: case insensitive (i)
\b      # Assert position at a word boundary
e       # Match the character “e” literally
\b      # Assert position at a word boundary
"

Upvotes: 2

Related Questions