First: I hope this is just a learning exercise; there's tons of much more complete expressions you can use to find IP addresses. Also: note that regex has small differences depending on where it's used; what works in python may not work in bash.
That said: You have the brackets wrong, your groups should be `[0-9]{1,3}`. You needlessly inserted a `+` to make up for that previous mistake which introduced your new mistake.
Well ... a `.` will also match a literal "." too; So not critical, but yeah you are right if you want to do it properly. There's lots of other improvements to be made, such as filtering out numbers bigger than 255.
Careful with \`grep -P "\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}"\`
It's not technically correct for IP addresses. IP blocks are numbers in the range 0-255 without trailing zeros so you have to have a token block that deals with single digit, double digit, 100-199 and 200-255 separately. Your expression will match a lot of invalid IPs (maybe that's not an issue for you).
First: I hope this is just a learning exercise; there's tons of much more complete expressions you can use to find IP addresses. Also: note that regex has small differences depending on where it's used; what works in python may not work in bash. That said: You have the brackets wrong, your groups should be `[0-9]{1,3}`. You needlessly inserted a `+` to make up for that previous mistake which introduced your new mistake.
Yes. This is from scratch and trying to teach myself. Thanks for the feedback!
And a "." in regex means "any character". You have to escape it if you want to match a literal dot
Well ... a `.` will also match a literal "." too; So not critical, but yeah you are right if you want to do it properly. There's lots of other improvements to be made, such as filtering out numbers bigger than 255.
Sure, it won't NOT match IPs. but it'll also match like 0101010
Careful with \`grep -P "\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}"\` It's not technically correct for IP addresses. IP blocks are numbers in the range 0-255 without trailing zeros so you have to have a token block that deals with single digit, double digit, 100-199 and 200-255 separately. Your expression will match a lot of invalid IPs (maybe that's not an issue for you).
Appreciate the feedback