0

Technically I need to implement parse_str() using regex. Though I will only extract one parameter value from a query. I have a string like a=val1&b=val2&c=val3

is it possible to get only the value of say b using preg_match also assuming b can be the last query (means the string can also be a=val1&b=val2)?

3
  • 1
    Stupid question: why can't you use parse_str() ? It's there since php 4 Commented May 30, 2013 at 18:22
  • Is there any particular reason you have to use regex? Commented May 30, 2013 at 18:25
  • yes actually, I have to use a modified version of PHP 5.3 and it strips off html tags for parse_str() call which I need to retain using my own parse_str() implementation. :( Commented May 30, 2013 at 18:30

1 Answer 1

2

Seems simple enough:

/(?:^|&)b=([^&]*)/

The value you want will be in the first capture group.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.