regex - Notepad++ 正则表达式

标签 regex notepad++

首先,正则表达式很可能是我处理过的最令人困惑的事情 - 话虽这么说,我不敢相信它们能如此高效。

所以我想在运气不好的情况下理解通配符正则表达式

需要转

f_firstname
f_lastname
f_dob       
f_origincountry 
f_landing  

进入

':f_firstname'=>$f_firstname,
':f_lastname'=>$f_lastname,
':f_dob'=>$f_dob,
':f_origincountry'=>$f_origincountry,   
':f_landing'=>$f_landing,

在回答中,您能否简要描述一下您正在使用的正则表达式,我一直在阅读教程,但它们让我感到困惑。谢谢。

最佳答案

编辑:正如克里斯指出的那样,您可以通过清除目标字符串中可能存在的任何空白来改进正则表达式。我也像他一样用 \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)

关于regex - Notepad++ 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12233815/

相关文章:

r - 如何提取子字符串作为 dplyr::mutate 管道的一部分

JavaScript 自动逗号

javascript - RegEx - 查找所有用引号括起来的字符串集

mysql - 如何使用 Regexp 进行复杂的字符串匹配?

Notepad++ "Move to Other View"向左移动,而不是向右移动

regex - Notepad++ 正则表达式搜索

Notepad++ 在下面使用 Sift + Enter 插入行,就像在 Eclipse 中一样?

regex - 使用 Vim 用另一个字符串替换所有 *非* 匹配的字符串

python - Notepad++ 转换为 UTF-8 多个文件

regex - Notepad++ 删除除匹配正则表达式之外的所有文本