[英]PHP Regex to grab a parameter value
Technically I need to implement parse_str() using regex. 从技术上讲,我需要使用正则表达式实现parse_str()。 Though I will only extract one parameter value from a query. 虽然我只会从查询中提取一个参数值。 I have a string like a=val1&b=val2&c=val3
我有一个字符串,如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
)? 是否有可能只使用preg_match得到b
的值,假设b可以是最后一个查询(意味着该字符串也可以是a=val1&b=val2
)?
Seems simple enough: 看起来很简单:
/(?:^|&)b=([^&]*)/
The value you want will be in the first capture group. 您想要的值将在第一个捕获组中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.