需要有关 php preg_match 的帮助
Need Help About php preg_match
我有一个字符串:
access":"YOU HAVE 0 BALANCE","machine
如何提取双引号之间的字符串并且只有文本(没有双引号):
YOU HAVE 0 BALANCE
我试过了
if(preg_match("'access":"(.*?)","machine'", $tok2, $matches)){
但运气不好 :( .
您可以使用
'/access":"(.*?)","machine/'
参见regex demo。您需要的值在组 1 中。
详情
access":"
- 文字子串
(.*?)
- 第 1 组:除换行字符外的任何 0+ 个字符,尽可能少,因为 *?
是惰性量词
","machine
- 文字子串
参见 PHP online demo:
$re = '/access":"(.*?)","machine/';
$str = 'access":"YOU HAVE 0 BALANCE","machine';
if (preg_match($re, $str, $matches)) {
print_r($matches[1]);
}
// => YOU HAVE 0 BALANCE
我有一个字符串:
access":"YOU HAVE 0 BALANCE","machine
如何提取双引号之间的字符串并且只有文本(没有双引号):
YOU HAVE 0 BALANCE
我试过了
if(preg_match("'access":"(.*?)","machine'", $tok2, $matches)){
但运气不好 :( .
您可以使用
'/access":"(.*?)","machine/'
参见regex demo。您需要的值在组 1 中。
详情
access":"
- 文字子串(.*?)
- 第 1 组:除换行字符外的任何 0+ 个字符,尽可能少,因为*?
是惰性量词","machine
- 文字子串
参见 PHP online demo:
$re = '/access":"(.*?)","machine/';
$str = 'access":"YOU HAVE 0 BALANCE","machine';
if (preg_match($re, $str, $matches)) {
print_r($matches[1]);
}
// => YOU HAVE 0 BALANCE