Regex to replace hyphen in the middle of a word
.net, regex
Solution
If I understand the question correctly, it's about matching the hyphen, not the words next to it. Here's a perl-like regex for that:
(?<=\w)-(?=\w)
That's a positive lookbehind assertion, one hyphen, and a positive lookahead assertion.
Problem
I need a regex to replace hyphens in the middle of any word but not to touch leading or trailing ones or standalone ones. This is for use in .NET within Regex.Replace() I've tried the following ``` \w[-]\w ``` but that also captures the character either side of the hyphen. As an example, what I need is for the following string -test test-test -test If the replace character was !, to become -test test!test -test Any help greatly received Thanks James