2

I am trying to figure out how I can put together a find and replace command with wildcards or figure out a way to find and replace the following example:

I would like to find terms that contain double quotes in front of them with a single quote at the end:

Example: find "joe' and replace with 'joe'

Basically, I'm trying to find all terms with terms having "in front and at the end.'

Jeff
  • 852
  • 7
  • 17
  • 28

1 Answers1

4

Check the [x] Regular expression checkbox in textpad's replace dialog and enter the following values:

Find what:

"([^'"]*)'

Replace with:

'\1'

Explanation:

In a regular expression, square brackets are used to indicate character classes. A character class beginning with a caret will match anything not in the class.
Thus [^'"] will match any character except ' and ". The following * indicates that any number of these characters can follow. The ( and ) mark a group. And the group we're looking for starts with " and ends with '. Finally in the replace string we can refer to any group via \n where n is the nth group. In our case it is the first and only group and that is why we used \1.

gollum
  • 2,472
  • 1
  • 18
  • 21
  • How can I additionally have it search for single quote with either a , or ; (comma or semicolon) in front of the single quote? – Jeff Feb 16 '16 at 23:32
  • I'm note quite sure what you mean. Give an example string please. – gollum Feb 16 '16 at 23:34
  • Search for `"([^'"]*)'([,;])` and, assuming you want to keep the `; ,` you'd replace it with `'\1'\2` – gollum Feb 16 '16 at 23:52