Home > Software design >  I want to use regex to extract nine digits from a string in Blueprism
I want to use regex to extract nine digits from a string in Blueprism

Time:08-10

I have the following string:

ABCD/SESSION REMARKS/SESSION REMARKS_002FT2213700215_ /CODTYPTR/049 //R101841246/058  Session 220517080                                                  REF: 02024741031486605002FT221

And i want to extract the nine digits that from "R101841246".

I have tried using Extract Regex in Utility - Strings of Blueprism, using the regex pattern (?<Lower>\d{9}) but the code is extracting 221370021, the first nine digits from SESSION REMARKS_002FT2213700215_.

I need a regex that will strictly extract nine consecutive digits and ignore occurrences where there is over nine digits

CodePudding user response:

here is one way do it

(?<=\/\/).(\d){9}(?=\/)

https://regex101.com/r/TYnSuP/1

(?<=//) : look behind for //
. : then any character
(\d){9} : capture the 9 digits
(?=/) : and lookahead /

CodePudding user response:

You can use

\bR-?(?<Lower>\d{9})\b

Here, it matches

  • \b - a word boundary
  • R - an R letter
  • -? - an optional hyphen
  • (?<Lower>\d{9}) - nine digits captured into Group "Lower"
  • \b - a word boundary.

See the regex demo.

  • Related