带有\w +的正则表达式模式及其行为 [英] Regular Expression Pattern with \w+ and its behaviour

查看:111
本文介绍了带有\w +的正则表达式模式及其行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释以下模式检查的内容???



((\w +)[^ \ s])+



用于以下输入

Y zsddfxdfsW.am i.dddfdfd是通过测试程序。好的,谢谢你。这只狗非常友好。



它有时可以部分完成并且有时完全。

Can someone explain what the following pattern checks for???

((\w+)[^\s])+

for the following input
"Y zsddfxdfsW.am i . dddfdfd is though tesing program. Getting Ok Thank YOU. This dog is very friendly."

it sometimes works partially and sometime completely.

推荐答案

前言

a)Take这里长途旅行?: http://www.regular-expressions.info/tutorial.html [ ^ ]

b)安装这个小工具,并使用它: http://www.weitz.de/regex-coach/ [ ^ ]



现在说明

\w 代表单词字符,通常是[A- ZA-Z0-9 _]。请注意包含下划线和数字。

[^ \s] 代表除空格之外的所有内容

同时()+ 意味着所有这些在一起至少可以重复一次



由于你有两个连续的字符类,你的匹配字符串需要至少有两个字符。每个奇怪的角色必须匹配第一个类,每个偶数角色必须匹配第二个。

输入中有许多子串符合这个(粗体是第一个):

Y zsddfxdfsW.am i。 dddfdfd 虽然 测试 程序。 获取 确定 谢谢 你。 这只狗 非常 友好。
Foreword
a) Take a long tour here?: http://www.regular-expressions.info/tutorial.html[^]
b) Install this little tool, and play with it: http://www.weitz.de/regex-coach/[^]

Now the explanation
\w stands for "word character", usually [A-Za-z0-9_]. Notice the inclusion of the underscore and digits.
[^\s] stands for everything but whitespaces
Whilst ()+ means that all this together can be repeated at least once

As you have two character classes consecutively, your matched string needs to have at least two characters. Every odd character has to match the first class, every even character has to match the second one.
There are many substrings in your input that match this (the bold one is the first):
"Y zsddfxdfsW.am i . dddfdfd is though tesing program. Getting Ok Thank YOU. This dog is very friendly."


这篇关于带有\w +的正则表达式模式及其行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆