[英]Javascript Regular Expression - Wacky String
I have a string (below) that I need to extract certain data between two characters. 我有一个字符串(下面),我需要在两个字符之间提取某些数据。
var str = "%T4271445443612318^MARK/Wdogn^14011011002033da?;411111111111111=140ke011lmn0529oqme00?";
I need to capture this number: 411111111111111
我需要捕获这个号码: 411111111111111
It is between a ";" 它介于“;”之间 and "=" always.
和“=”总是。
Any help I am still new to RegEx. 任何帮助我仍然是RegEx的新手。
This would be ;(\\d+)=
这将是
;(\\d+)=
http://www.regular-expressions.info/javascriptexample.html is your friend. http://www.regular-expressions.info/javascriptexample.html是你的朋友。 :)
:)
how about something like 怎么样的
;(\d+)=
which does the following: 执行以下操作:
;
;
char \\d+
matches one or more numeric char \\d+
匹配一个或多个数字字符 (
and )
capture the number into a capturing group (
和)
将数字捕获到捕获组中 =
matches the equals char at the end =
匹配最后的等号char var fourOneOne = str.match(/;(\d+)=/)[0];
If it's always formatted as you suggest, you don't need a regex: 如果它总是按照你的建议格式化,你不需要正则表达式:
var str = "%T4271445443612318^MARK/Wdogn^14011011002033da?;411111111111111=140ke011lmn0529oqme00?";
var sub = str.substring(str.indexOf(';')+1,str.indexOf('='));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.