If I have a string like this:
“word1 ‘word2’ word3”
is it possible to use a regex replace to change the string to this:
“word1 word3 ‘word2′”
I know what word1 and word3 will be, but do not know what word2 will be, but it will always be in single quotes.
You can replace
"word1 ('\w+') word3"with"word1 word3 \1". The replace syntax might be different in other regex engines; I’m using .NET’s which is based on Perl’s.\w+matches a series of word characters, aka a word. You can change this if it does not fit your definition of word;\1in the replace string means to use group one from the match,\2means group two, etc.