A
A
Alexey2021-09-20 10:49:15
Regular Expressions
Alexey, 2021-09-20 10:49:15

Regular expression, after number, no letters?

It is necessary that the regular expression does not work if there is a letter after the number
example https://regex101.com/r/wqU35y/1
it is necessary that the text 2333a does not fall under the condition

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexandroppolus, 2021-09-20
@akhx

option 1: "super-greedy search" - we fill the numbers into the piggy bank, take the result and add a check that there is no further letter. Here the trick is that there is no backtracking, the chain of numbers will roll back. There is no special syntax for "overgreedy" in JS, but perhaps your language does. option 2: checking that the numbers are not followed by "numbers and then a letter" Offhand, the first option looks faster, because there is a linear complexity, and in the second it seems to be quadratic (although one cannot say for sure: maybe the mechanism will somehow guess not to do it vlob )
(?=(\d+))\1(?![a-z])
(\d+)(?!\d*[a-z])

V
Viktor Taran, 2021-09-20
@shambler81

Alexandroppolus

(\d+)(?!\d*[az])

(\d+)(?!\d*\w$) az I think you can safely change, well, add $
for everyone
, but you can even shorter
(?=\d+$)\d+
or even
(?=\d+$).+
I think this can go for the simplest solution

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question