How can I write a Regex to represent certain keywords without any letter/number following or preceding them? (symbols and spaces are optional)
I tried to write this, but it's doesn't seem to work:
let resWord = "[class|function|static|this|return]"
let keyword = new Regex("[^[^a-zA-Z0-9]]"+resWord+"[^[a-zA-Z0-9]$]")
I'm new to Regex, so please excuse me if it's a stupid question :)
This can be accomplished using negative look aheads and behinds
(?<![a-zA-Z0-9])(class|function|static|this|return)(?![a-zA-Z0-9])
or with out them.
([^a-zA-Z0-9])(class|function|static|this|return)([^a-zA-Z0-9])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With