我有这个字符串:
# userid name uniqueid connected ping loss state rate
# 529 2 "arioch83" STEAM_1:0:86796179 55:58 99 0 active 80000
# 619 3 "Snake" STEAM_1:0:27678629 06:42 61 0 active 80000
# 622 4 "Captain_Selleri" STEAM_1:1:47927314 03:25 44 0 active 80000
# 583 5 "krN[786]" STEAM_1:1:14638235 28:53 53 0 active 128000
# 621 6 "Giack" STEAM_1:1:67468100 04:44 129 0 active 80000
# 326 7 "Urkrass" STEAM_1:0:55150382 3:02:31 51 0 active 80000
#613 "Vinny" BOT active
# 584 9 "Tkappa" STEAM_1:0:32266787 27:55 360 0 active 80000
# 605 10 "Narpok19" STEAM_1:0:44838130 14:36 67 0 active 80000
# 551 11 "robbetto83" STEAM_1:1:63675894 50:10 86 0 active 80000
# 530 12 "XxKazuyaxX" STEAM_1:0:18676379 55:57 68 0 active 80000
# 623 13 "beut3d - Keyser Söze" STEAM_1:0:14500718 00:29 70 0 active 80000
# 602 15 "Homroy" STEAM_1:1:7870901 16:34 169 0 active 80000
# 607 16 "[Bloody]Eagle" STEAM_1:1:59567346 09:14 77 0 active 80000
#615 "Jeff" BOT active
# 587 18 "Heisenberg" STEAM_1:1:61427218 25:15 81 0 active 80000
#end
我想在“#用户ID名称uniqueid连接ping丢失状态速率”和“ #end”之间获取字符串。我根据在stackoverflow上发现的内容尝试了几种正则表达式,但没有用:(这是我最后的尝试
var matches = text.match(/# userid name uniqueid connected ping loss state rate(.+)\&#end/);
if (matches.length > 1) {
alert(matches[1]);
}
如您所见,我对正则表达式一无所知...关于它们的任何优秀教程?
谢谢,
您需要能够跨多行进行匹配。您正在寻找s
(dotall)修饰符。不幸的是,此修饰符在JavaScript中不存在。常见的解决方法是将点替换.
为以下内容:
[\S\s]
因此,您可以使用以下正则表达式:
/# userid name uniqueid connected ping loss state rate([\S\s]*?)#end/
说明:
( # group and capture to \1:
[\S\s]*? # any character of:
# non-whitespace (all but \n, \r, \t, \f, and " "),
# whitespace (\n, \r, \t, \f, and " ")
# (0 or more times matching the least amount possible)
) # end of \1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句