Regex pattern to choose data BETWEEN matching quotation marks
c#, regex, vb.net
Solution
Busted my brain to work this one out, turns out that specifying non-word boundaries `\B` does the trick:
Regex
`\B("[^"]*)-([^"]*")\B`
Replacement
`$1 $2`
Demo
http://regex101.com/r/dS0bH8
Problem
Suppose I had the following string I wanted to run a Regular expression on: ``` This is a test string with "quotation-marks" within it. The "problem" I am having, per-se, is "knowing" which "quotation-marks" go with which words. ``` Now, suppose I wanted to replace all the `-` characters between the quotation marks with, say, a space. I was thinking I could do so with a regex looking as follows: ``` Find What: (\"[^"]*?)(\-)([^"]*?\") Replace With: $1 $3 ``` The problem I'm having is that using this pattern, it does not take into account whether a quotation mark was opening or closing the statement. So, in the example above, the `-` character in `per-se` will be replaced by a space since it is between 2 quotation marks, but between a closing and an opening mark - When I specifically want to look within the text between an opening and a closing mark. How do you account for this in such a regular expression? I hope this makes sense. I'm using VB / C# Regex. Just to complete the question (and hopefully elaborate a bit more if necessary), the end result I would like to get would be: ``` This is a test string with "quotation marks" within it. The "problem" I am having, per-se, is "knowing" which "quotation marks" go with which words. ``` Thanks!!