84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
有点特殊需求,需要一条表达式取出html中N个字段数据比如
xxx xxx xxx xxx
xxx
需要在html中取出title以及pic的数据 正则该怎么写呢?中间的
业精于勤,荒于嬉;行成于思,毁于随。
You don’t have to use regular expressions, there is something called phpquery
let str = ` xxx xxx xxx xxx ` let results = str.match(/(title|pic)">.*?e.replace('">', ':')).map(e=>e.replace('<', ''))
The result is:
// results: [ 'title:xxx', 'pic:xxx', 'title:xxx', 'pic:xxx' ]
Supplement:I didn’t see clearly that the question mentioned PHP. I don’t know much about PHP. It’s written in js. You can just take the regular part.
Just upload the code
$re = '/(title|pic).*?>([^<]+)/'; $str = ' xxx xxx xxx xxx '; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); //演示输出的结果,你可以根据你的需求,从$matches中拿到你想要的xxx部分。 var_dump($matches);
This kind of performance is very poor -.-. It is still reliable to use js to obtain it at the front desk.
You don’t have to use regular expressions, there is something called phpquery
The result is:
Supplement:
I didn’t see clearly that the question mentioned PHP. I don’t know much about PHP. It’s written in js. You can just take the regular part.
Just upload the code
This kind of performance is very poor -.-. It is still reliable to use js to obtain it at the front desk.