Visual Studio Regex积累/Notepad++ Regex积累

vs2013 regex基础匹配:

符号含义范例
.any sinle charactora.o matches “aro”
*Match zero or more occurrences of the preceding expression (match as many characters as possible)
貌似只能匹配a或者r,不能像.*可以在中间匹配其他字符
a*r matches
“r” in “rack”,
“ar” in “ark”,
“aar” in “aardvark”
+Match one or more occurrences of the preceding expression (match as many characters as possible)e.+e matches
“eede” in “feeder”
but not “ee”.
用+比用*,可以避免匹配一些莫名其妙的地方
.*Match any character zero or more times (Wildcard *)c.*e matches
“cke” in “racket”,
“comme” in “comment”,
and “code” in “code”
\s匹配一个空格width\s 匹配 "width "
[0-9]匹配指定范围内的所有字符匹配数字
[a-z]匹配指定范围内的所有字符be[n-t] matches
“bet” in “between”,
“ben” in “beneath”,
and “bes” in “beside”, but not “below”.
[a-z_]匹配制定范围内的所有字符匹配“WX_2_QT”中的"WX_"和“_QT”
^Anchor the match string to the beginning of a line or string^car matches the word “car” only when it appears at the beginning of a line.
()Capture and implicitly number the expression contained within parenthesis
[^abc]Match any character that is not in a given set of charactersbe[^n-t] matches “bef” in “before”, “beh” in “behind”, and “bel” in “below”, but not “beneath”.
{x}Specify the number of occurrences of the preceding character or groupx(ab){2}x matches “xababx”, and x(ab){2,3}x matches “xababx” and “xabababx” but not “xababababx”.
匹配定长字符串:
.{6}
匹配6个字符
\r?$Anchor the match string to the end of a lineend\r?$ matches “end” only when it appears at the end of a line.

vs2013 regex函数式、表达式匹配与替换:

匹配目标替换结果匹配表达式替换表达式说明
m_MainWnd.width = 800;m_MainWnd.setWidth(800);width.+\s([0-9]+)setWidth($1).+匹配多个字符
\s匹配单个空格
([0-9]+) 捕捉了数字部分
用$number进行替换
m_StsWnd.y = -1;m_StsWnd.setY(-1);y.+\s([0-9-]+)setY($1)进阶:用
([0-9-]+)
匹配了负数
m_iTaraPosSize.x = m_pMetrics->m_TaraWnd.width - 3;m_iTaraPosSize.setX(m_pMetrics->m_TaraWnd.width - 3);x.=\s([0-9a-z-._>() ]+);setX($1)进阶:用
[a-z0-9->._() ]+
来匹配
m_iTaraPos[5].x = m_iTaraPos[6].x - SWdispDotX;m_iTaraPos[5].setX(m_iTaraPos[6].x - SWdispDotX);x.+=\s([0-9a-z-._>()\[\]+ ]+);setX($1)进阶:用
x.+=\s([0-9a-z-._>()\[\]+ ]+);
多匹配[]

notepad++ regex基础匹配:

符号含义范例
(…)<Parentheses mark a subset of the regular expression. The string matched by the contents of the parentheses ( ) can be re-used as a backreference or as part of a replace operation;
[^…]The complement of the characters in the set. For example, [^A-Za-z] means any character except an alphabetic character.Care should be taken with a complement list, as regular expressions are always multi-line, and hence [^ABC]* will match until the first A,B or C (or a, b or c if match case is off), including any newline characters. To confine the search to a single line, include the newline characters in the exception list, e.g. [^ABC\r\n].
+This matches 1 or more instances of the previous character, as many as it can. For example, Sa+m matches Sam, Saam, Saaam, and so on. [aeiou]+ matches consecutive strings of vowels.\s+
matches 1 or more spaces
*This matches 0 or more instances of the previous character, as many as it can. For example, Sa*m matches Sm, Sam, Saam, and so on.For example, Sa*m matches Sm, Sam, Saam, and so on.

notepad++ regex函数式、表达式匹配与替换:

匹配目标替换结果匹配表达式替换表达式说明
zero_bmp BITMAP DISCARDABLE “…/…/font/bmpfont/0.bmp”<file alias=“zero_bmp”>bmpfont/0.bmp</file>

^([^} \r\n])\s+BITMAP DISCARDABLE ".{11}([^}\r\n])"\r?$

<file alias="$1">$2</file>[^…]匹配除了…的字符

notepad++ regex替换所有注释

替换空行:
\n\n
替换为
\n

删除空行:
^\s+\n
替换为

替换单行的{:
\n{
替换为
{

替换单行/**/:
/*(.*?)*/
替换为

替换多行/**/:
选中替换对话框的’matches new line’
/*(.*?)*/
替换为

替换//:
1//[^\n]\n
替换为

javascript regex函数式:

符号含义范例
\转义(escape)\. 由于.是特殊字符,所以需要转义
/正则表达式的开始和结束str.search("/\./") 搜索句号.

grep perl regex函数式:

匹配目标匹配表达式说明
http://a.gz
https://b.gz
https?😕/\K[^ ]+s?
匹配0个或多个s,as few as possible
http://a.gz
https://b.gz
ftp://c.gz
https?😕/[^ ]+|ftp://[^ ]+|
匹配pattern a or pattern b

  1. \t ↩︎

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值