[英]Find term with asterisk *
I have a big string with html:我有一个大字符串 html:
$html = '...hello{"text":"52"},{"text":" watching"}world...';
I want to search in $html
with:我想在$html
中搜索:
{"text":"*"},{"text":" watching"}
So I can get the number (where the asterisk is)?这样我就能得到号码(星号在哪里)? In my example, it is 52
, but it can be any number.在我的例子中,它是52
,但它可以是任何数字。
I should end up with $number
equal 52
.我应该以$number
等于52
结束。 Is regex the appropriate route?正则表达式是合适的路线吗?
You can try (?<=\{"text":")(\d+)(?="\},\{"text":" watching"\})
你可以试试(?<=\{"text":")(\d+)(?="\},\{"text":" watching"\})
With:和:
(?<=\{"text":")
: the positive lookbehind you're looking for (belongs to {"text":"
) (?<=\{"text":")
:您正在寻找的正面回顾(属于{"text":"
)(\d+)
: the digits you need (belongs to *
) (\d+)
:你需要的数字(属于*
)(?="\},\{"text":" watching"\})
: the positive lookahead you're looking for (belongs to "},{"text":" watching"}
) (?="\},\{"text":" watching"\})
:你正在寻找的正面前瞻(属于"},{"text":" watching"}
)https://regex101.com/r/5eqI2e/1 https://regex101.com/r/5eqI2e/1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.