Skip to content

Commit 2b4c50d

Browse files
committed
enhance(regex): improve IP extractor to prevent false positives and enforce IPv4 octet ranges
Tighten IPv4 pattern to enforce 0-255 per octet, rejecting invalid addresses like 256.256.256.256 and 999.999.999.999 Replace loose IPv6 matcher with comprehensive pattern covering full, compressed, link-local with zone IDs, and IPv4-embedded forms
1 parent b230527 commit 2b4c50d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Specialized Areas/Regular Expressions/IP Address Validation/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
The regex in `getIP4OrIPV6address.js` validates both IPv4 and IPv6 addresses in input text.
1+
This snippet extracts IPv4 and IPv6 addresses from free text. For single-value validation, see `validateIPInput.js` and `Validate IPv6 Address/script.js`.
2+
3+
The regex in `getIP4OrIPV6address.js` finds both IPv4 and IPv6 addresses within arbitrary text content.
24

35
IPv6 coverage includes:
46
- Full addresses like `2001:0db8:85a3:0000:0000:8a2e:0370:7334`

Specialized Areas/Regular Expressions/IP Address Validation/getIP4OrIPV6address.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Extracts IPv4 and IPv6 addresses from arbitrary text content
2+
// For single-value validation, use validateIPInput.js or Validate IPv6 Address/script.js
13
extractIPAddresses: function(text) {
24
var ipv4 = "(?:25[0-5]|2[0-4]\\d|1?\\d?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1?\\d?\\d)){3}";
35
var ipv6 = "("+

0 commit comments

Comments
 (0)