mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-14 10:06:58 -04:00
Added look ahead and look behind to avoid over capture.
This commit is contained in:
parent
0c01c6a7c3
commit
e9b182d33b
1 changed files with 8 additions and 4 deletions
|
@ -67,12 +67,16 @@ class ExtractIPAddresses extends Operation {
|
||||||
const [includeIpv4, includeIpv6, removeLocal, displayTotal, sort, unique] = args,
|
const [includeIpv4, includeIpv6, removeLocal, displayTotal, sort, unique] = args,
|
||||||
|
|
||||||
// IPv4 decimal groups can have values 0 to 255. To construct a regex the following sub-regex is reused:
|
// IPv4 decimal groups can have values 0 to 255. To construct a regex the following sub-regex is reused:
|
||||||
ipv4DecimalByte = "(?:25[0-5]|2[0-4]\\d|1?[1-9]\\d|\\d)",
|
ipv4DecimalByte = "(?:25[0-5]|2[0-4]\\d|1?[0-9]\\d|\\d)",
|
||||||
ipv4OctalByte = "(?:0[1-3]?[0-7]{1,2})",
|
ipv4OctalByte = "(?:0[1-3]?[0-7]{1,2})",
|
||||||
|
|
||||||
// Each variant requires exactly 4 groups with literal . between
|
// Look behind and ahead will be used to exclude matches with additional decimal digits left and right of IP address
|
||||||
ipv4Decimal = "(?:" + ipv4DecimalByte + "\\.){3}" + "(?:" + ipv4DecimalByte + ")",
|
lookBehind = "(?<!\\d)",
|
||||||
ipv4Octal = "(?:" + ipv4OctalByte + "\\.){3}" + "(?:" + ipv4OctalByte + ")",
|
lookAhead = "(?!\\d)",
|
||||||
|
|
||||||
|
// Each variant requires exactly 4 groups with literal . between.
|
||||||
|
ipv4Decimal = "(?:" + lookBehind + ipv4DecimalByte + "\\.){3}" + "(?:" + ipv4DecimalByte + lookAhead + ")",
|
||||||
|
ipv4Octal = "(?:" + lookBehind + ipv4OctalByte + "\\.){3}" + "(?:" + ipv4OctalByte + lookAhead + ")",
|
||||||
|
|
||||||
// Then we allow IPv4 addresses to be expressed either entirely in decimal or entirely in Octal
|
// Then we allow IPv4 addresses to be expressed either entirely in decimal or entirely in Octal
|
||||||
ipv4 = "(?:" + ipv4Decimal + "|" + ipv4Octal + ")",
|
ipv4 = "(?:" + ipv4Decimal + "|" + ipv4Octal + ")",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue