Shahid Karimi
Shahid Karimi

Reputation: 4357

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+

Upvotes: 0

Views: 51

Answers (2)

Aaron
Aaron

Reputation: 24812

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)[^)]*

Upvotes: 0

Lucas Araujo
Lucas Araujo

Reputation: 1688

Try this regex:

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

See the demo below.

Regex Demo

Upvotes: 3

Related Questions