Skip to main content
Question

Help with extracting a regex

  • February 15, 2024
  • 1 reply
  • 299 views

Forum|alt.badge.img+5
  • Navigator | Tier 3
  • 15 replies

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

Tamil Arasu10
Most Valuable Pathfinder
Forum|alt.badge.img+18
  • Most Valuable Pathfinder
  • 3295 replies
  • February 19, 2024

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.