I have a regular expression that match the string that contains the word "duration", followed by a < or > operator and then a number. Here is the expression:


Is there any way I can make this expression better?

  • 2
    \$\begingroup\$ Can you give some example input and output text? \$\endgroup\$
    – Zack
    May 10, 2016 at 3:05

2 Answers 2


Since you only have two characters to compete with, namely, < and >, use a character set. Other than that, you might consider \d matching your digits, instead of 0-9 as \d covers the numerical characters across the entire UTF8 range.

The final expression would be:


I've left the matching groups in place, considering that you might be referencing them in your later code.


Since you have only duration keyword after that either < or > sign & then the 1 or more numeric value then use below one regex which simple.


I removed the character which are not required.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.