Answer the question
In order to leave comments, you need to log in
How to optimize the search for the amount before the word "ruble"?
Hello. There is a line:
Reservation No. 372 12343.22 dated June 24, 21. The cost of living is 1000.32 rubles. as well as a commission of 500 rubles.
I did this: /[0-9.]*.(?=руб.)/g
, however regex101 says he did 579 steps. I understand this is a lot and probably the code can be optimized somehow. Tell me how?
I need to get 2 matches: 1000.32 and 500
Plus, my regular expression also gets a space after the sum. He's not needed
Answer the question
In order to leave comments, you need to log in
\d+
can be changed to \d++
\d++(?:\.\d+)?(?=\s*руб\.)
https://regex101.com/r/vxphzh/2
Or add (*SKIP)
\d+(*SKIP)(?:\.\d+)?(?=\s*руб\.)
https://regex101.com/r/vxphzh/3
/(\d+(?:\.\d+)?) руб\./g
Although, perhaps, I missed something, I haven’t practiced for a long time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question