简体   繁体   English

javascript查找字符串中子字符串的第3次出现

[英]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)/

RegEx Demo 正则演示

Or if paTeND text is know known then grab the value after 3rd | 或者,如果已知已知paTeND文本,则在3rd |之后获取值| :

^(?:[^|]*\|){3}([^|;]+)

and use captured group #1. 并使用捕获的#1组。

Demo 2 演示2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javascript regexp在字符串末尾找到第三个字符 - javascript regexp find 3rd char at the end of the string 使用javascript增加字符串中第三次出现的数字 - Increment 3rd occurence of digit in string with javascript 开发 JavaScript 以查找给定字符串“efg”第 3 次出现的 position I/P:abcefgacefgabcceftyefghjklop O/p:20 - Develop a JavaScript to Find the position of 3rd occurrence of the given string “efg” I/P:abcefgacefgabcceftyefghjklop O/p:20 javascript 正则表达式替换字符串中的第一个和第三个空格 - javascript regex replace 1st and 3rd space in a string Javascript:模糊地找到字符串中的子字符串 - Javascript: Fuzzily find substring in string 在javascript中字符串的最后3个位置添加一个字符 - Add a character at the 3rd last position of the string in javascript 使用Javascript将子字符串位置查找到字符串中 - Find substring position into string with Javascript 使用 lodash 从数组中查找 substring 并将它们推送到另一个,然后将结果与第三个表进行比较 - use lodash to find substring from array and to push them to another and then to compare result with the 3rd table Javascript->递归地找到字符串中的子字符串 - Javascript -> Recursively find a substring within a string 在javascript中使用regexp查找并删除字符串中的子字符串 - find and remove substring in string using regexp in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM