简体   繁体   English

Jscript正则表达式在斜线之间获取文本

[英]Jscript regex to get text between slashes

Trying to create regex to extract part of the string with use of jscript/jquery I am noob in both :P 尝试创建正则表达式以使用jscript / jquery提取字符串的一部分,我在两个方面都是菜鸟:P

String pattern : 字符串模式

A..Z/CB..C/ABC+BCD/ABCD/TextToGet1/TextToGet2/1-9/1-9 A..Z / CB..C / ABC + BCD / ABCD / TextToGet1 / TextToGet2 / 1-9 / 1-9

text to get is after 4th slash and 5th slash [TextToGet1] and [TextToGet2] 要获取的文本位于第4个斜杠和第5个斜杠之后[TextToGet1]和[TextToGet2]

thx 谢谢

How about using split instead, since it is by / that you want your results like: 如何使用split代替,因为它是按/ ,因此您希望得到如下结果:

var result = " A..Z/CB..C/ABC+BCD/ABCD/TextToGet1/TextToGet2/1-9/1-9".split('/')

result[4] //outputs TextToGet1

and

result[5] //outputs TextToGet2

^(?:[^\/]*\/){4}([^\/]+)\/([^\/]+)

The matches in group1 and group2 组1和组2中的匹配项

Demo 演示

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM