$str = "Hello, welcome to [ARGS1]. We will ship to you immediately, address: [ARGS2]";
How to get [ARGS1] and [ARGS2]; Is it normal to match?
The regular level is a bit rotten, /^(\[)*(\])$/ is there a problem with matching?
Please advise!
Reply content:
$str = "Hello, welcome to [ARGS1]. We will ship to you immediately, address: [ARGS2]";
How to get [ARGS1] and [ARGS2]; Is it normal to match?
The regular level is a bit rotten, /^(\[)*(\])$/ is there a problem with matching?
Please advise!
JavaScript Edition
With match
var str = '你好,欢迎使用[args1].我们会马上给你发货,地址:[args2]';var re = /\[\w+\]/g;var matches = str.match(re);console.log(matches[0],matches[1]);
With exec
var str = '你好,欢迎使用[args1].我们会马上给你发货,地址:[args2]';var re = /\[\w+\]/g;while((matches =re.exec(str)) != null){ console.log(matches[0]);}
It's complicated.
var str = '你好,欢迎使用[args1].我们会马上给你发货,地址:[args2]';var re = /[\u4e00-\u9fa5]/;console.log(str.split(re).filter(function(value){return /\[\w+\]/.test(value)}))
You also need to make a simple return array.
Article: JavaScript Regular expressions
Regular expression Notes
PHP version
Preg_match
"; echo $matches[2]."
";}?>
Preg_match_all
"; echo $matches[0][1]."
";}?>
Related article: strings and regular Expressions in PHP