rooot_999
rooot_999

Reputation: 366

How to combine two regex's

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.

Upvotes: 0

Views: 67

Answers (2)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626826

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

Upvotes: 1

Quinn
Quinn

Reputation: 4504

You also could try:

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

DEMO

Upvotes: 0

Related Questions