Search code examples
regexperlparsingtext

How to escape parenthesis in Perl Regular Expressions?


If I have a string such as:

 JOURNAL   Yeast 10 (11), 1503-1509 (1994)

How do I get the two numbers in the parenthesis( 11 and 1994) ? One way I attempted was using:

/\s+JOURNAL\s+.*\((\d+).*\((\d+))/

but this doesn't work. So my two questions:

  1. How to escape the parenthesis so I can use match them in the RE ?

  2. How to get the above two numbers ?

I am doing this in Perl. Thanks for any help !


Solution

  • Try this

    \((\d+)\)
    

    Regex demo

    Explanation:
    \: Escapes a special character sample
    ( … ): Capturing group sample
    +: One or more sample