search

Home  >  Q&A  >  body text

javascript - regular expression Q&A

var reg=/([^&=]+)=([^&=]*)/ig;

Please help me explain the above regular expression; it can match the name/value pairs in the query string, but I really don’t understand it. What kind of matching rule is this? ?
For example, &name=bob&age=10, it can match name=bob and age=10

仅有的幸福仅有的幸福2735 days ago901

reply all(1)I'll reply

  • 三叔

    三叔2017-06-28 09:29:59

    Let me try to explain it:

    //ig means ignore case, global search

    For details, see: js regular expression object

    ([^&=]+)=([^&=]*)

    This regular expression can be divided into 3 parts:

    1) ([^&=]+)

    means matching 1 to n (n>1) characters that are not '&', '='

    2) =
    means matching = sign (only one)

    3) ([^&=]*)

    has similar meaning to 1), but the number expressed is different:

    Match 0 to n (n is any positive integer) non-'&', '=' characters

    The following points need to be noted here:

    a) Regular expression quantifier

    b) Regular expression grouping and grouping returns in different modes

    Finally, regular expressions are not an easy concept to get started with. A few questions or situations will not allow you to use it skillfully. It is recommended to think more and ask more questions.

    reply
    0
  • Cancelreply