Reputation: 382
When searching for d
For example
" D"
= true" D "
= true"D"
= true "[D!"
= true"ad!"
= false"sadness"
= false"sa d!ness"
= trueUpvotes: 3
Views: 1425
Reputation: 336158
You're probably looking for word boundary anchors:
\bd\b
matches d
only if it isn't adjacent to other alphanumerics.
Note that the definition of "alphanumeric" varies between regex engines. Most define them as the character set [A-Za-z0-9_]
, but some also include non-ASCII letters/digits.
Upvotes: 4
Reputation: 785156
You can use lookarounds:
(?<![A-Za-z0-9])[Dd](?![A-Za-z0-9])
Which means match d
or D
which is not preceded or followed by [A-Za-z0-9]
.
Upvotes: 4