How to obtain the content in a string?

Source: Internet
Author: User
$ 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.