0

I want to combine these regex's so I can have the right result, my point is the regex should use ( or ) so if the number was "(45.29 SAR ) or ( 4,523.88 SAR)"

here is the two regex that i've used :

\b\d+\.\d+\p{Zs}+SAR\b

\b\d+\,\d+\.\d+\p{Zs}+SAR\b

Example explain what I mean

Thank you.

rooot_999
  • 366
  • 2
  • 3
  • 13
  • I think you need [`\b\d{1,3}(?:,\d{3})*\.\d+\p{Zs}+SAR\b`](https://regex101.com/r/pZ9eC6/1). No round brackets, right? – Wiktor Stribiżew Mar 29 '16 at 17:09
  • Possible duplicate of [RegEx matcing numeric values with or without thousand separators](http://stackoverflow.com/questions/6248621/regex-matcing-numeric-values-with-or-without-thousand-separators) – user140547 Mar 29 '16 at 17:11
  • Example goes here, as text, and not somewhere else in an image. How can we copy/paste the examples to use for testing if they're not in your question as text? Images should only be used when there is absolutely no other way to demonstrate an issue. – Ken White Mar 29 '16 at 17:11
  • @WiktorStribiżew Thanks a lot man that works. – rooot_999 Mar 29 '16 at 17:27

2 Answers2

1

You may use a *-quantified group of a comma followed with 3 digits:

\b\d{1,3}(?:,\d{3})*\.\d+\p{Zs}+SAR\b

See the regex demo

Explanation:

  • \b - leading word boundary
  • \d{1,3} - 1 to 3 digits
  • (?:,\d{3})* - 0 or more groups of a comma followed with 3 digits
  • \. - aliteral comma
  • \d+ - 1+ digits
  • \p{Zs}+ - 1+ horizontal whitespace
  • SAR\b - whole word SAR
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
0

You also could try:

/\b\d+[.,]\d+(?:\.\d+)?\p{Zs}+SAR\b/g

DEMO

Quinn
  • 4,394
  • 2
  • 21
  • 19