RegEx @programming.dev sabreW4K3 @lazysoci.al 2mo ago Why won't this work? (?<!\d)\d+\.\d+ should match the numbers at the end of the lines and yet it won't. What am I doing wrong?
(?<!\d)\d+\.\d+ should match the numbers at the end of the lines and yet it won't. What am I doing wrong?
To put this into easier form:(nota digit) (1ormore digit) (literal dot) (1ormore digit)As far as I can see in that text, none of them end with "5.4” or "3.6” or "0.0”, so no your regex wont workMaybe change the middle " \d+" into "\d*" , or surround the "\d+." with a question mark group?
surround the “\d+” with a question mark group?If you're expecting decimals, that's the preferred solution:(?<!\d)(\d+\.)?\d+(?=\s*$)Otherwise you could do simply(?<!\d)\d+(?=\s*$)I added the lookahead (?=\s*$) to match digits at the end of the line only with possible trailing spaces.
Thank you. Every time someone shows me something regarding regex, I feel like I'm getting lessons from a deity.You actually helped me out lots. I switched it to (?<!\d)\.*\d{1}+ thanks to your comment and it kinda did the job, so thank you.
What am I doing wrong?Not specifying the regex engine you use, first of all. Second, also describe what you mean by numbers that you want to match.
Not specifying the regex engine you useSorry, I have no clue.Second, also describe what you mean by numbers that you want to match.So you see in the screenshot, there's a random number at the end of some of the lines, I'm trying to match that.
BTW if you don't need to capture the number, \d$ should match what you need. If regex syntax supports \d, of course.
Sorry, I have no clue.What do you use to apply your regex? Programming language, library, command line tool etc.there’s a random number at the end of some of the lines, I’m trying to match that.Is it decimal? One digit or multiple digits? Natural, rational?
To put this into easier form:
(nota digit) (1ormore digit) (literal dot) (1ormore digit)
As far as I can see in that text, none of them end with "5.4” or "3.6” or "0.0”, so no your regex wont work
Maybe change the middle " \d+" into "\d*" , or surround the "\d+." with a question mark group?
If you're expecting decimals, that's the preferred solution:
(?<!\d)(\d+\.)?\d+(?=\s*$)
Otherwise you could do simply
(?<!\d)\d+(?=\s*$)
I added the lookahead
(?=\s*$)
to match digits at the end of the line only with possible trailing spaces.Whaaaaaaa, thank you!
Thank you. Every time someone shows me something regarding regex, I feel like I'm getting lessons from a deity.
You actually helped me out lots. I switched it to
(?<!\d)\.*\d{1}+
thanks to your comment and it kinda did the job, so thank you.oh nice solution, quite elegant