Home > OS >  Need RegularExpression to retrieve quantity number from the end of the sentence
Need RegularExpression to retrieve quantity number from the end of the sentence

Time:02-02

I've string data like this.

CFV - Certificat les Fondamentaux du Vin (en présentiel)(5)()

I want to retrieve the number from the second last bracket. This can be any number or numbers. I need help to get the right regex expression. The condition are followed:

  1. It can be any numbe
  2. r. No special character or string
  3. I only need the number. or an empty string.

CodePudding user response:

This regex gives you the number between the second last parentheses:

/(?<=\()\d (?=\)\(\)$)/

Explanation:

(?<=\()llok behind for a (

\d match one or more digits

(?=\)\(\)$) look ahead for )()

CodePudding user response:

Try

^(. \s )(............)(\d{0,5})

result in group 3. regex checks for 0 - 5 digits in the given ()

see Demo for more explanation

  •  Tags:  
  • Related