Can anyone suggest a regex to match the underscore in the following examples:
test_test test[_test test_]
But NOT match this:
test[_]test
This is using the .Net Regular Expression library. I’m using this RegEx tester to check:
http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx
Try this:
It consists of an alternation of
_[^\]](underscore and not]) and[^[]_(not[and underscore).Or if you want to use look-around assertions to really match just the underscore and not surrounding characters:
This matches any underscore that is not followed by a
]((?=[^\]]), positive look-ahead) or any underscore that is not preceded by a[((?<=[^[]_), negative look-behind). And this can be combined to: