[英]Regular expression to get the string including the starting character
我有这样的字符串
var str="|Text|Facebook|Twitter|";
我试图得到任何一个单词与其前面的管道标志,如此类似
|Text
或|Facebook
或|Twitter
我想到了两种模式,但它们没有用
/|Facebook/g //returned nothing
/^|Facebook/g // returned "Facebook" but I want "|Facebook"
我应该用什么来获取|Facebook
?
管道是正则表达式中的特殊字符。 A|B
匹配A
或 B
你必须逃避管道匹配|
从字面上。
var str = '|Text|Facebook|Twitter|'
str.match(/\|\w+/g) // => ["|Text", "|Facebook", "|Twitter"]
\\w
匹配任何字母,数字, _
。
你应该逃避|
焦炭:
/\|Facebook/g
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.