$ Str & quot; Hello, welcome to [args1]. we will ship the goods to you immediately. The address: [args2] & quot; how to obtain [args1] and [args2]; is it generally a regular expression matching? Regularizedlevel is a bit bad, ^ ([) * (]) $ is there a problem with matching? Please advise! $ Str = "Hello, welcome to [args1]. We will ship the goods to you right away. Address: [args2]";
How can I obtain [args1] and [args2]? Is it a regular expression that is usually used for matching?
Regularizedlevel is a little bad,/^(\[)*(\])$/What about the matching problem?
Please advise!
Reply content:
$ Str = "Hello, welcome to [args1]. We will ship the goods to you right away. Address: [args2]";
How can I obtain [args1] and [args2]? Is it a regular expression that is usually used for matching?
Regularizedlevel is a little bad,/^(\[)*(\])$/What about the matching problem?
Please advise!
Match for JavaScript
Var str = 'hello, welcome to [args1]. we will ship the goods to you immediately. Address: [args2] '; var re =/\ [\ w + \]/g; var matches = str. match (re); console. log (matches [0], matches [1]);
Use exec
Var str = 'hello, welcome to [args1]. we will ship the goods to you immediately. Address: [args2] '; var re =/\ [\ w + \]/g; while (matches must re.exe c (str ))! = Null) {console. log (matches [0]);}
Complicated
Var str = 'hello, welcome to [args1]. we will ship the goods to you immediately. Address: [args2] '; var re =/[\ u4e00-\ u9fa5]/; console. log (str. split (re ). filter (function (value) {return/\ [\ w + \]/. test (value )}))
You also need to make the returned array simple.
Article: JavaScript Regular Expression
Regular Expression notes
PHP preg_match
"; Echo $ matches [2]."
";}?>
Preg_match_all
"; Echo $ matches [0] [1]."
";}?>
Related Articles: strings and regular expressions in php