Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression: Match a string not immediately preceded by or followed by a alphanumeric character

Tags:

regex

When searching for d

For example

  • " D" = true
  • " D " = true
  • "D" = true
  • "[D!" = true
  • "ad!" = false
  • "sadness" = false
  • "sa d!ness" = true
like image 753
BallisticPugh Avatar asked Dec 01 '25 04:12

BallisticPugh


1 Answers

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].

RegEx Demo

like image 114
anubhava Avatar answered Dec 03 '25 23:12

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!