[英]Notepad++ regular expressions
First of all, regular expressions are quite possibly the most confusing thing I have every dealt with - with that being said I cannot believe how efficient they can make ones life. 首先,正则表达式很可能是我每次处理的最令人困惑的事情 - 据说我无法相信它们能够有效地生活。
So I am trying to understand the wildcard regex with no luck 所以我试图理解通配符正则表达式没有运气
Need to turn 需要转
f_firstname
f_lastname
f_dob
f_origincountry
f_landing
Into 成
':f_firstname'=>$f_firstname,
':f_lastname'=>$f_lastname,
':f_dob'=>$f_dob,
':f_origincountry'=>$f_origincountry,
':f_landing'=>$f_landing,
In the answer can you please briefly describe the regex you are using, I have been reading the tutorials but they boggle my mind. 在答案中,您可以简要描述一下您正在使用的正则表达式,我一直在阅读这些教程,但是我们一直在思考。 Thanks. 谢谢。
Edit : As Chris points out, you can improve the regex by cleaning up any white space there may be in the target string. 编辑 :正如克里斯所指出的,你可以通过清理目标字符串中可能存在的任何空白来改进正则表达式。 I also replace the dot with \\w
as he did because it's better practice than using the .
我也用\\w
替换了点,因为它比使用它更好.
Search: ^f_(\w+)\s*$
^ # start at the beginning of the line
f_ # look for f_
(\w+) # capture in a group all characters
\s* # optionally skip over (don't capture) optional whitespace
$ # end of the line
Replace: ':f_\1'=>$f_\1,
':f_ # beginning of replacement string
\1 # the group of characters captured above
'=>$f_ # some more characters for the replace
\1, # the capture group (again)
Find: (^.*)
Replace with: ':$1'=>$$1,
Find What: 找什么:
(f_\w+)
Here we're matching f_
followed by a word character \\w+
(the plus mean one or more times). 这里我们匹配f_
后跟一个单词字符\\w+
(加号意味着一次或多次)。 Wrapping the whole thing in brackets means we can reference this group in the replace pattern 将整个事物包含在括号中意味着我们可以在替换模式中引用该组
Replace With: 用。。。来代替:
':\1'=>$\1,
This is simply your result phrase but instead of hardcoding the f words I've put \\1
to reference the group in the search 这只是你的结果短语,而不是硬编码我在文章中使用\\1
来引用搜索中的组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.