There is such a regular season - (\d*) грн|руб|р.|\$\U

It should parse the full price with a currency like - 500 руб . But instead, I will receive only the currency itself, that is, the руб . What is the problem?

  • try replacing the space with \ w and appending \ w to the beginning of the regular season. - pavel
  • @pavel Nothing has changed. - Vlad
  • How exactly is this regular season called? - Grundy
  • Yes, the number is also included in the first alternative, that is, 500 UAH would show true - Grundy
  • (\d*)\s(грн|руб|р.) something like that. - pavel

2 answers 2

Here is another option:

 /\$\d+(?:\.\d+)?|\d+(?:\.\d+)?\x20+(?:грн|руб|р.|\$)/iu 

Test here: https://regex101.com/r/hD3qA8/1

\$\d+(?:\.\d+)? - capture prices in dollars of the form: $100 , $99.99

\d+(?:\.\d+)?\x20+(?:грн|руб|р.|\$) - capture prices with leading digits + from 1 to infinity gaps + name of the currency.

PS If you need a group to capture, then after / put an opening parenthesis and a closing /iu close.

    (\ $? [\ d. \,] \ s *) (\ $ | rub UAH UAH | p)?

    • You at least would bring the link to the example of the test, but not on mine. And look at the inappropriate behavior of this example: regex101.com/r/kB3tC8/1 - Visman