[英]javascript find 3rd occureance of a substring in a string
I am trying to extract the substring between 3rd occurance of '|' 我试图提取“ |”的第三次出现之间的子字符串 character and ';GTSet' string within string 字符串中的字符和'; GTSet'字符串
For Example, if my string is "AP0|#c7477474-376c-abab-2990-918aac222213;L0|#0a4a23b12-125a-2ac2-3939-333aav111111|ABC xxx;pATeND|#222222ANCJ-VCVC-2262-737373-3838383"; 例如,如果我的字符串是“ AP0 |#c7477474-376c-abab-2990-918aac222213; L0 |#0a4a23b12-125a-2ac2-3939-333aav111111 | ABC xxx; pATeND |#222222ANCJ-VCVC-2262-737373-3838383” ;
I would like to extract "ABC xxx" from above string using javascript. 我想使用javascript从上述字符串中提取“ ABC xxx”。 I have tried following options 我尝试了以下选项
var str = "AP0|#c7477474-376c-abab-2990-918aac222213;L0|#0a4a23b12-125a-2ac2-3939-333aav111111|ABC xxx;pATeND|#222222ANCJ-VCVC-2262-737373-3838383"; alert(str.match(/^|\\;pATeND(.*)$/gm)); //var n = str.search(";pATeND"); //to get the 3rd occurance of | character //var m = str.search("s/\\(.\\{-}\\z|\\)\\{3}");
This lookahead regex should work: 这个先行的正则表达式应该工作:
/[^|;]+(?=;pATeND)/
Or if paTeND
text is know known then grab the value after 3rd |
或者,如果已知已知paTeND
文本,则在3rd |
之后获取值|
: :
^(?:[^|]*\|){3}([^|;]+)
and use captured group #1. 并使用捕获的#1组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.