[英]What is this regex doing?
I thought this regex was about turning words into an array, but I get null as a result我认为这个正则表达式是关于将单词转换为数组,但结果是 null
when I want to get the second word from "facebox otherword" with array[0]当我想用数组 [0] 从“facebox otherword”中获取第二个单词时
This is the regex:这是正则表达式:
this.rel.match(/facebox\[?\.(\w+)\]?/)
Thanks Richard谢谢理查德
http://xenon.stanford.edu/~xusch/regexp/analyzer.html is a simple regex analyzer (among many others). http://xenon.stanford.edu/~xusch/regexp/analyzer.html是一个简单的正则表达式分析器(等等)。
Since its not linkable
, here is
just
a screenshot and the link :
由于它不可链接
,这里
只是
一个截图和链接:
I believe you are looking for is the split() function:我相信您正在寻找的是split() function:
What you mentioned about turning words into an array is typically referred to as a split , so if you wanted to get " otherword
" from " facebox otherword
", you would do the following:您提到的将单词转换为数组通常称为split ,因此如果您想从“
facebox otherword
”中获取“ otherword
”,您可以执行以下操作:
var test = "facebox otherword"
var word = test.split(' ')[1];
Your regex matches:您的正则表达式匹配:
facebox.abc脸盒.abc
facebox[.abc脸盒[.abc
facebox[.abc]脸盒[.abc]
facebox.abc] facebox.abc]
with abc
being at least one "word character" (letters, digits, and underscores). abc
至少是一个“单词字符”(字母、数字和下划线)。
Note \.
注意
\.
. . That means that it is a dot, rather than any character.
这意味着它是一个点,而不是任何字符。 This regex cathches
facebox.otherword
这个正则表达式捕获
facebox.otherword
This matches text like:这匹配如下文本:
facebox[.blabla]
facebox.blabla
The regex you have there won't match "facebook otherword", because of the \.
由于
\.
. . It's looking for a literal ".", so it would match the following: "facebook.otherword", "facebook[.otherword", "facebook.otherword]", or "facebook[.otherword]".
它正在寻找文字“.”,因此它将匹配以下内容:“facebook.otherword”、“facebook[.otherword”、“facebook.otherword]”或“facebook[.otherword]”。
Checks that the string contained in the rel
property of this
检查包含在
this
的rel
属性中的字符串
If matched, the 1 or more word characters will be contained in a sub-match.如果匹配,则 1 个或多个单词字符将包含在子匹配中。
/facebox\[?\.(\w+)\]?/
facebox
literalfacebox
字面量[
[
.
.
]
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.