我只是在没有转义分隔符的情况下尝试拆分值。
我已经在StackOverflow上阅读了很多关于此的问题,但对我来说没什么用。
我有这个值:
InvalidMsg(this,'error with this caracter \', please change your value.');
这里的关键字是:\'
我想收到错误消息,所以我尝试了类似的内容:
var str = "InvalidMsg(this,'error with this caracter \', please change your value.');";
matches = str.match(/([^']|\\')+/g);
alert(matches[1]); //error with this caracter
我需要得到完整的信息..
完整的信息是:
error with this caracter ', please change your value
任何想法?
谢谢
答案 0 :(得分:1)
尝试以下正则表达式,并使用非捕获组
在匹配的组中查找结果(.*)(?:,')(.*)\\('.*)(?:'\);)
输入:
InvalidMsg(this,'error with this caracter \', please change your value.');
匹配
InvalidMsg(this
error with this caracter
', please change your value.
示例代码:
var re = /(.*)(?:,')(.*)\\('.*)(?:'\);)/g;
var str = 'InvalidMsg(this,\'error with this caracter \', please change your value.\');';
var subst = '$2$3';
var result = str.replace(re, subst);
输出:
error with this caracter ', please change your value.
答案 1 :(得分:1)