Skip to main content

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)/R0-9]{2}/20-9]{2}/20-9]{3}/30-9]{5}) but  RQ/12/12/123/12345 gets extracted with the R from Ref. included 

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