tl;dr
In RubyMine you can use find and replace with capture groups
(.*?)
and backreferences$1
(if you have several groups:$[Capture-Group ID]
).
Named captures(?<text>.*)
are also supported.
If you want to replace double quotes with single quotes, replacing every "
with a '
is prone to errors. Regular expressions can help you out here.
.*
icon next to the "find" field)."(.*?)"
. Your regular expression captures whatever is contained by two double quotes.'$1'
. The $1
references what was captured.RubyMine shows you a preview of the result, so you can check if the find and replace is working like expected.
You may use the ↑
and ↓
icon buttons next to the replace field to cycle through matches.
In this example, we will be using named captures. If you are new to named captures, we suggest reading the excellent Named Capturing Groups and Backreferences Guide on regular-expressions.info Show archive.org snapshot .
You have an attribute that holds a URL. Now you want to change this attribute to hold a list of URLs, and need to adjust all tests.
Our goal is to convert the url "..."
to the urls ["..."]
here.
url (?<url>.*?)
url
" at the beginning of the string is just a text fragment; the (?<url>.*?)
is our named capture group.urls ["${url}"]
urls
" is just a text fragment; ${url}
references the named capture, and ["${url}"]
means that it's put into quotes and brackets.(\S*?)\.should\s*?==
. Your regular expression captures any non-whitespace character that directly precedes .should
, followed by any amount of whitspace characters and ==
. For other matchers you need to replace the ==
accordingly.expect($1).to eq
. The $1
references is what was captured. For other matchers you need to replace the eq
accordingly.Bonus: If your coding styles require you to pass method arguments in parantheses, you could use a second capture group
(\S*?)\.should\s*?==\s*?('.*?')
.expect($1).to eq($2)
.:(\w*) =>
$1: