Regular Expression-How to Write php Regular Expression matching

Source: Internet
Author: User
Tags php regular expression
How to write the token value dwwewee in & quot; userasdasd; tokendwwewee; typeassdfs & quot; in php? I really don't want to write .. This does not seem to work. {code...} I want to retrieve the token value in the string "user = asdasd; token = dwwewee; type = assdfs" dwwewee,
How to Write php?
I really don't want to write ..

This does not seem to work either.

preg_match("/(token=)(.*?)(;|$)/i","user=asdasd; token=dwwewee; type=assdfs", $matches);foreach ($matches as $m){    echo $m;echo "
";}

Reply content:

I want to retrieve the token value in the string "user = asdasd; token = dwwewee; type = assdfs" dwwewee,
How to Write php?
I really don't want to write ..

This does not seem to work either.

preg_match("/(token=)(.*?)(;|$)/i","user=asdasd; token=dwwewee; type=assdfs", $matches);foreach ($matches as $m){    echo $m;echo "
";}

(?<=token=).*(?=;)

if (preg_match("/(token=)(.*?)(;|$)/i","user=asdasd; token=dwwewee; type=assdfs", $matches)) {    print_r($matches[2]);}

If the matching is successful, the results will be stored in the $ matches array. index 0 is the matching complete string, 1 is your first bracket, 2 is the second bracket, and so on. From your perspective, the value you need appears in the second bracket, so the value $ matches [2]

php//php5.6 echo explode('=',explode(';',$str)[1])[1];//dwwewee$arr = explode(';',"user=asdasd; token=dwwewee; type=assdfs");$arr2 = explode('=',$arr[1]);echo $arr2[1];//dwwewee

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.