0
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+

2 Answers 2

3

Try this regex:

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

See the demo below.

Regex Demo

Sign up to request clarification or add additional context in comments.

Comments

0

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

5 Comments

Watch out, this will match any characters, not just digits.
Indeed, added a digit-only alternative.
this one is uselessly too slow due to lookbehind. the one posted by ibarros is better imho
plus he said " integer" not "anything other than )" so again a useless [^)] that will check all characters not just the integers.
Ok I switched the main code and its alternative. You're right about the slowness, but some people will prefer having the whole logic implemented in the regex rather than having to select a specific group afterwards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.