简体   繁体   English

如何:在 PhpStorm 的查找和替换中使用正则表达式

[英]How to: RegEx in PhpStorm's Find & Replace

I have this batch process where I need to refactor svg path's.我有这个批处理过程,我需要重构 svg 路径。 Because I have many occurrences in my project and I'm a lazy guy, I prefer to solve this task with find and replace as Regular Expression.因为我的项目中出现了很多情况并且我是一个懒惰的人,所以我更喜欢使用 find 和 replace 作为正则表达式来解决这个任务。

What I have:我拥有的:

<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/_ui/desktop/common/images/svg/icons.svg#icon-arrow--white"></use>

What I want in the end:我最终想要的是:

<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-arrow--white"></use>

My regex looks like this:我的正则表达式如下所示:

xlink="(.*)#

and its valid for my string on http://regex-testdrive.com/en/dotest and other sites.它对我在http://regex-testdrive.com/en/dotest和其他网站上的字符串有效。

How come, that if I use this expression in PhpStorm that it is not valid.怎么会,如果我在 PhpStorm 中使用这个表达式,它是无效的。 If someone of you guys could provide me a hint, why I get 0 occurrences in PhpStorm with my RegEx, I'd be glad.如果你们中有人可以给我一个提示,为什么我的 RegEx 在 PhpStorm 中出现 0 次,我会很高兴。

You can use:您可以使用:

xlink:href="[^"]*"

And replace the occurences with xlink:href="#icon-arrow--white" , see a demo on regex101.com .并用xlink:href="#icon-arrow--white"替换出现的情况,请参阅regex101.com 上的演示

Next to the field where you input your search string (in your case your regex), there's a box to enable regex in search:在您输入搜索字符串的字段(在您的情况下是您的正则表达式)旁边,有一个框可以在搜索中启用正则表达式:

在此处输入图片说明

Simply check Regex , the regex is working then.只需检查Regex ,然后正则表达式就可以工作了。

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

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