简体   繁体   中英

PHP Regular expression to extract data from a url source

URL: somedoamin.com/r?ammem/hlaw:@field(DOCID+@lit(hj0011))

How can I extract the didit after hj, that is 001;

The format will always be @lit(hj<integer>))

Please help

I tried regular expression

\s+(lit)\d+

Try this regex:

@lit\(hj(\d+)\)\)

See the demo below.

Regex Demo

I would use the following :

(?<=@lit\(hj)\d*

It uses a positive look-behind to check for preceding @lit(hj and captures every digit up to the next closing parenthesis.

Try it here !

An alternative that captures anything up to the next parenthesis :

(?<=@lit\(hj)[^)]*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM