Reputation: 4251
I want to use PHPStorm to find and replace all instances of:
[A-z]['][s]
Example:
Andy's
or David's
to:
Andy\'s
or David\'s
I have the regex as above, but I want to know how to use the found character in the regex in the replace.
Upvotes: 0
Views: 348
Reputation: 5271
There are several problems with the regex the way you have it:
[A-z]['][s]
You can't use a shortcut [A-z]
to get a range of all upper and lower. You need to use [A-Za-z]
. You also don't need the apostrophe and s in brackets:
[A-Za-z]'s
Then, to replace with a matched group, use $ groups:
([A-Za-z])'s
, replacing with $01\\\\'s
Upvotes: 1
Reputation: 4251
The $
character is used to access the array of regex groups.
The regex groups can be defined with brackets.
This works:
Find: ([A-z/0-9])['][s]
Replace: $01\\\\'s
(To print one slash, 4 are needed.)
Upvotes: 0