简体   繁体   English

PHPStorm Regex用回叫替换

[英]PHPStorm Regex Replace with back calls

I want to use PHPStorm to find and replace all instances of: 我想使用PHPStorm查找和替换以下所有实例:

[A-z]['][s]

Example: 例:

Andy's or David's Andy'sDavid's

to: 至:

Andy\\'s or David\\'s Andy\\'sDavid\\'s

I have the regex as above, but I want to know how to use the found character in the regex in the replace. 我有上面的正则表达式,但是我想知道如何在替换中使用在正则表达式中找到的字符。

There are several problems with the regex the way you have it: [Az]['][s] 正则表达式的使用方式有几个问题: [Az]['][s]

You can't use a shortcut [Az] to get a range of all upper and lower. 您不能使用快捷方式[Az]来获取所有上限和下限的范围。 You need to use [A-Za-z] . 您需要使用[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 ([A-Za-z])'s ,替换为$01\\\\\\\\'s

The $ character is used to access the array of regex groups. $字符用于访问正则表达式组的数组。

The regex groups can be defined with brackets. 正则表达式组可以用方括号定义。

This works: 这有效:

Find: ([Az/0-9])['][s] 查找: ([Az/0-9])['][s]

Replace: $01\\\\\\\\'s 替换: $01\\\\\\\\'s


(To print one slash, 4 are needed.) (要打印一个斜杠,需要4个。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM