Question

Help with extracting a regex

  • 15 February 2024
  • 1 reply
  • 66 views

Badge +5

Can someone help with extracting Q/12/12:123/12345 from Ref No. Q/12/12/123/12345 using regex. I am currently using the replace function with Regex  (^(Q|R)/[0-9]{2}/[0-9]{2}/[0-9]{3}/[0-9]{5}) but  RQ/12/12/123/12345 gets extracted with the R from Ref. included 


1 reply

Userlevel 6
Badge +15

Hi @s 9425 ,

Please try with below option,

\b(Q|RQ)/\d{2}/\d{2}:\d{3}/\d{5}\b

  • \b: Word boundary to ensure that we match whole words.
  • (Q|RQ): Match either "Q" or "RQ".
  • /\d{2}/: Match a forward slash followed by two digits.
  • \d{2}:\d{3}/: Match two digits, a colon, three digits, and a forward slash.
  • \d{5}: Match five digits.
  • \b: Word boundary at the end to ensure the complete match

Now you can use this regex pattern in your replace function. It should correctly extract the desired reference number without including the "R" from "Ref." in the match.

 

 

Reply