Let's start with a simple regex that matches a set of four 3-digit number seperated by a dot. The regex is: (\d{1,3})\.(\d{1,3}).(\d{1,3}).(\d{1,3})
The problem with this regex is that it matches numbers that are outside the range of Ip address (255). 135.19.780.192 is one such incorrect entry.
184.151.243.192 - Valid 135.19.780.192 - Invalid 104.102.169.42 - Valid 271.47.185.84 - Invalid 62.26.180.265 - Invalid 104.102.169.42 - Valid
match | position | $1 | $2 | $3 | $4 |
---|---|---|---|---|---|
184.151.243.192 | 0 | 184 | 151 | 243 | 192 |
135.19.780.192 | 24 | 135 | 19 | 780 | 192 |
104.102.169.42 | 49 | 104 | 102 | 169 | 42 |
271.47.185.84 | 72 | 271 | 47 | 185 | 84 |
62.26.180.265 | 96 | 62 | 26 | 180 | 265 |
104.102.169.42 | 120 | 104 | 102 | 169 | 42 |
Let's first find the pattern for first number of the 4-set in each of the row
Add ^ and options g and m to focus only on the first number.
184.151.243.192 - Valid 135.19.780.192 - Invalid 104.102.169.42 - Valid 271.47.185.84 - Invalid 62.26.180.265 - Invalid 104.102.169.42 - Valid
match | position | $1 |
---|---|---|
184. | 0 | 184 |
135. | 24 | 135 |
104. | 49 | 104 |
62. | 96 | 62 |
104. | 120 | 104 |
Now that it matches the first part correctly. Let's repeat the same thrice followed by number without dot to complete this.
We can remove the ^ and m as we don't need it anymore.
We should add the word boundary marker as it would set the exact area to apply the pattern.
184.151.243.192 - Valid 135.19.780.192 - Invalid 104.102.169.42 - Valid 271.47.185.84 - Invalid 62.26.180.265 - Invalid 104.102.169.42 - Valid
match | position | $1 | $2 | $3 |
---|---|---|---|---|
184.151.243.192 | 0 | 243. | 243 | 192 |
104.102.169.42 | 49 | 169. | 169 | 42 |
104.102.169.42 | 120 | 169. | 169 | 42 |
If we don't want the group capturing, we can disable it as follows:
184.151.243.192 - Valid 135.19.780.192 - Invalid 104.102.169.42 - Valid 271.47.185.84 - Invalid 62.26.180.265 - Invalid 104.102.169.42 - Valid
match | position |
---|---|
184.151.243.192 | 0 |
104.102.169.42 | 49 |
104.102.169.42 | 120 |
To activate the ^
and $
combination in every line, select the Multiline option(m).
12Hr format
12:45 AM 15:30 20:45 9:15 AM 11:30 PM 08:18 AM
match | position | $1 |
---|---|---|
12:45 AM | 0 | 12 |
9:15 AM | 21 | 9 |
11:30 PM | 29 | 11 |
08:18 AM | 38 | 08 |
24Hr format
12:45 AM 15:30 20:45 9:15 AM 11:30 PM 08:18 AM
match | position | $1 |
---|---|---|
15:30 | 9 | 15 |
20:45 | 15 | 20 |