0
Regex question, a range of numbers between two delimiters
How do I fix this regular expression so that it finds all running numbers from 0 to 255 in the middle of # and ; ? #0; = True #255; = True #256; = False #abc; = False #-1; = False I tried this but it doesn't work: #[0-255]; but nothing. Regex101: https://regex101.com/
11 Réponses
+ 3
I have experimented a little bit and have come up with the following expression
#([01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5]);
+ 2
this is not beautiful. but it works.
/#\b([01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5]);/gm
https://regex101.com/r/jEBRVW/3
how to break down number range for regex:
https://www.regextutorial.org/regex-for-numbers-and-ranges.php
+ 1
So I tried both and both meet the requirements, thank you both, I will check the first who answered me, I would like to put them both, thank you very much to both Ani Jona 🕊 ravilnicki , regexes are as useful as they are complicated!
0
That is unfortunately not quite that simple. You will need to check individually in the range of 250 to 255, the range of 200 to 249, as well as the range of 0 to 199. This may further be complicated whether or not a leading zero is allowed in the numbers.
0
Ani Jona 🕊 The leading 0 like 025 for example can be fine, so I explicitly convert it into a number later. Do you know how I can check the ranges described by you ?
0
I don't understand, why is it not correct?
0
Ok