使用一个正则表达式测试多个单词

时间:2019-06-14 11:06:17

标签: javascript regex

我有一个正则表达式,我想向它传递多个单词,然后将与表达式匹配的字符串还给我。我该怎么做(使用香草JS,没有jQuery等)?

let regEx = /\^[a-zA-Z0-9]+\-[a-zA-Z0-9]+\|[a-zA-Z0-9]+/
let str1 = "5"
let str2 = "df-df-01"
let solutions = [str1,str2].HOW(regEx) //I'd like this to return ["df-df-01"]

1 个答案:

答案 0 :(得分:2)

您正在寻找 //the string values from my db is: // $registrationdate= "13/06/2019 15:06:06"; // $expirydate="14/06/2019 16:46:00"; //this example uses the third option if ($expirydate != null || $expirydate != ''){ // creates DateTime objects $datetime = new DateTime(); //the line below is the problem, it cant convert the string to object $datetime1 = $datetime->createFromFormat('d/m/Y H:i:00', $registrationdate); //however, this line below works, although both are strings $datetime2 = $datetime->createFromFormat('d/m/Y H:i:00', $expirydate); if ($datetime1!= false && $datetime2 != false){ // calculates the difference between DateTime objects $interval = date_diff($datetime1, $datetime2); // printing result in days format $validityperiod= $interval->format('%r%a'); } else $validityperiod = ""; } + filter

test

还要注意固定的正则表达式。