读书人

以次正则为什么能找到数字

发布时间: 2013-09-05 16:02:06 作者: rapoo

以下正则为什么能找到数字?
正则式 “[.$&)(\]\[\\~^%|*+?}{"' `#!-@=<>,;:/]+”,如果要匹配字符串"abshd{.^[]|\" ;/we3~6t4~!ty"的话,匹配结果中会包含数字,这是为什么?我用Regex Match Tracer做的测试。
[解决办法]
别似乎,再认真查查资料。要确认,别靠记忆。
[解决办法]

引用:
方括号里面似乎只有[]\需要转义,但如果是转义的问题,正则式里那项的问题导致数字也能被匹配?

-如果是第一个或者最后一个的话 不需要转义,否则还得加上转义
看regexbuddy的分析


[.$&)(\]\[\\~^%
[解决办法]
*+?}{"' `#!-@=<>,;:/]+

Match a single character present in the list below ?[.$&)(\]\[\\~^%
[解决办法]
*+?}{"' `#!-@=<>,;:/]+?
Between one and unlimited times, as many times as possible, giving back as needed (greedy) ?+?
One of the characters “.$&)(” ?.$&)(?
A ] character ?\]?
A [ character ?\[?
A \ character ?\\?
One of the characters “~^%
[解决办法]
*+?}{"' `#” ?~^%
[解决办法]
*+?}{"' `#?
A character in the range between “!” and “@” ?!-@?
One of the characters “=<>,;:/” ?=<>,;:/?


Created with RegexBuddy

[解决办法]
将-放在[]的最后

读书人网 >C++

热点推荐