sabreW4K3@lazysoci.al to RegEx@programming.dev · 1 month agoWhy won't this work?lazysoci.alimagemessage-square12linkfedilinkarrow-up19arrow-down10file-text
arrow-up19arrow-down1imageWhy won't this work?lazysoci.alsabreW4K3@lazysoci.al to RegEx@programming.dev · 1 month agomessage-square12linkfedilinkfile-text
(?<!\d)\d+\.\d+ should match the numbers at the end of the lines and yet it won’t. What am I doing wrong?
minus-squaretetris11@lemmy.mllinkfedilinkarrow-up9·edit-21 month agoTo 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?
minus-squarea14o@feddit.orglinkfedilinkarrow-up5·1 month ago 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.
minus-squaresabreW4K3@lazysoci.alOPlinkfedilinkarrow-up3·1 month agoThank 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.
minus-squaresabreW4K3@lazysoci.alOPlinkfedilinkarrow-up2·17 days agoIt’s a terrible solution, but it works somewhat. Thanks for being nice.
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
It’s a terrible solution, but it works somewhat. Thanks for being nice.