Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 正则表达式澄清_Javascript_Jquery_Regex_Scripting - Fatal编程技术网

Javascript 正则表达式澄清

Javascript 正则表达式澄清,javascript,jquery,regex,scripting,Javascript,Jquery,Regex,Scripting,我有以下java脚本来提取字符串中“=”后面的单词 例如: string strOld="ActionDate=11/20/2014 12:00:00 AM "; strOld.substr(strOld.indexOf(type)).substr(type.length +1, strOld.substr(strOld.indexOf(type)).substr(type.length).indexOf(" ")) 这将从上述字符串中提取“11/20/2014”。因为这是出现在“=”之后的

我有以下java脚本来提取字符串中“=”后面的单词

例如:

string strOld="ActionDate=11/20/2014 12:00:00 AM ";

strOld.substr(strOld.indexOf(type)).substr(type.length +1, strOld.substr(strOld.indexOf(type)).substr(type.length).indexOf(" "))
这将从上述字符串中提取“11/20/2014”。因为这是出现在“=”之后的单词

如何使用正则表达式重写

我想得到逗号分隔的日期,以防在同一字符串变量中再次出现“=”

如果有多个标志:

输入:string strOld=“ActionDate=11/20/2014 12:00:00 AM SuspensionCode=123”;
输出:“11/20/2014123”

这是一个javascript版本

刚刚了解了jshell,似乎是个不错的工具

var myregexp = /=(\S*)/g;
var match = myregexp.exec("FirstEvictionActionDate=11/20/2014 12:00:00 AM SuspensionCode=123");
while (match != null) {
  //for (var i = 0; i < match.length; i++) {
    alert((match[1]));
  //}
  match = myregexp.exec("FirstEvictionActionDate=11/20/2014 12:00:00 AM SuspensionCode=123");
}
var myregexp=/=(\S*)/g;
var match=myregexp.exec(“firstexecutionactiondate=11/20/2014 12:00:00 AM SuspensionCode=123”);
while(匹配!=null){
//对于(变量i=0;i
这是一个javascript版本

刚刚了解了jshell,似乎是个不错的工具

var myregexp = /=(\S*)/g;
var match = myregexp.exec("FirstEvictionActionDate=11/20/2014 12:00:00 AM SuspensionCode=123");
while (match != null) {
  //for (var i = 0; i < match.length; i++) {
    alert((match[1]));
  //}
  match = myregexp.exec("FirstEvictionActionDate=11/20/2014 12:00:00 AM SuspensionCode=123");
}
var myregexp=/=(\S*)/g;
var match=myregexp.exec(“firstexecutionactiondate=11/20/2014 12:00:00 AM SuspensionCode=123”);
while(匹配!=null){
//对于(变量i=0;i
首先将字符串拆分为数组,然后从数组中的第二项(即日期时间字符串)中提取日期

var strOld = "ActionDate=11/20/2014 12:00:00 AM";
var arr = strOld.split('=');
var regex = /([\d]{2}\/[\d]{2}\/[\d]{4})\s([\d]{2}:[\d]{2}:[\d]{2}\s(AM|PM))/;
var result;
arr[1].replace(regex, function(date, time) {
    result = date;
    console.log(result);
});

首先将字符串拆分为数组,然后从数组中的第二项提取日期,即datetime字符串

var strOld = "ActionDate=11/20/2014 12:00:00 AM";
var arr = strOld.split('=');
var regex = /([\d]{2}\/[\d]{2}\/[\d]{4})\s([\d]{2}:[\d]{2}:[\d]{2}\s(AM|PM))/;
var result;
arr[1].replace(regex, function(date, time) {
    result = date;
    console.log(result);
});

如果您不关心等号左边的单词,则可以使用此正则表达式将其拆分:

'ActionDate=11/20/2014 12:00:00 AM SuspensionCode=123'.split(/\w+=/);
// result: ["", "11/20/2014 12:00:00 AM ", "123"]
或者,如果要将它们包括在数组中,请尝试以下操作:

'ActionDate=11/20/2014 12:00:00 AM SuspensionCode=123'.split(/(\b\w+)=/)
// result ["", "ActionDate", "11/20/2014 12:00:00 AM ", "SuspensionCode", "123"]

如果您不关心等号左边的单词,则可以使用此正则表达式将其拆分:

'ActionDate=11/20/2014 12:00:00 AM SuspensionCode=123'.split(/\w+=/);
// result: ["", "11/20/2014 12:00:00 AM ", "123"]
或者,如果要将它们包括在数组中,请尝试以下操作:

'ActionDate=11/20/2014 12:00:00 AM SuspensionCode=123'.split(/(\b\w+)=/)
// result ["", "ActionDate", "11/20/2014 12:00:00 AM ", "SuspensionCode", "123"]

@巴克利:这个
=(\S+)
就足够了。。而且你还必须添加
g
modifier.Single可以工作,但是multiple我放了下面的表达式,但是它不工作这个工作的var myregexp=/.*?=(.*)\s/i;但是我不想要日期中的时间部分,只要日期就足够了,而且没有逗号@buckley this
=(\S+)
就足够了。。而且你还必须添加
g
modifier.Single可以工作,但是multiple我放了下面的表达式,但是它不工作这个工作的var myregexp=/.*?=(.*)\s/i;但是我不想要日期中的时间部分,只要日期就足够了,而且没有逗号