Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rautamiekka/e6e088f085a553778992dfd9e1ffb2da to your computer and use it in GitHub Desktop.
Save rautamiekka/e6e088f085a553778992dfd9e1ffb2da to your computer and use it in GitHub Desktop.
IPv4 universal complete RegEx with options
NOTE: Each RegEx is a single line and Java users, for example, need to mind Java's additional requirements (such as escaping escape characters), otherwise they should work in every RegEx flavor.
This code ain't my work originally, I modified it.
-------------------------------------------------------------------------
No support to get the individual sections:
```
(?:[1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.(?:[1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.(?:[1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.(?:[1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
```
With support to get each section with match groups 1-4
```
([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment