我想拆分这条线:
at myFunc http://mysite.com/test.php:13:24
进入这个:
at myFunc http://mysite.com/test.php
13
24
我试过使用正则表达式(见下文)但它们是错误的:
line.split( /[^http]:/ );
line.split( /[^http][:]/ );
line.split( /(?!http):/ );
line.split( /(?!http)[:]/ );
我该怎么做?
最佳答案
JavaScript 没有回顾 :(
技巧:反转字符串
var reverse = function(s) { return s.split('').reverse().join(''); };
var parts = reverse(line).split( /:(?!ptth)/ ).map(reverse).reverse();
调整问题 #1:匹配冒号后面没有//
var parts = line.split( /:(?!\/\/)/ );
调整问题 #2:只匹配最后两个冒号
var parts = line.match( /(.*):(.*):(.*)/ ) ;
parts.shift();
关于javascript - 如何在冒号上拆分此行(在 JavaScript 中),除非冒号前面有 http 或 https?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17129418/