---
title: "常用正则表达式"
author: "z610"
date: "2013-09-05T15:49:41Z"
tags: ["正则表达式"]
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2013-09-05T15:49:41Z"
id: 1936927
url: "https://z610.iteye.com/blog/1936927"
---

IP: 

/^(?:(?:25\[0-5]|2\[0-4]\[0-9]|1\[0-9]\[0-9]|\[1-9]?\[0-9])\\.){3}(?:25\[0-5]|2\[0-4]\[0-9]|1\[0-9]\[0-9]|\[1-9]?\[0-9])$/

 

IP with sub mask

/^(?:(?:25\[0-5]|2\[0-4]\[0-9]|1\[0-9]\[0-9]|\[1-9]?\[0-9])\\.){3}(?:25\[0-5]|2\[0-4]\[0-9]|1\[0-9]\[0-9]|\[1-9]?\[0-9])(?:/(3\[0-2]|2\[0-9]|1\[0-9]|\[1-9]))?$/

 

IP range

/(^(?:(?:25\[0-5]|2\[0-4]\[0-9]|1\[0-9]\[0-9]|\[1-9]?\[0-9])\\.){3}(?:25\[0-5]|2\[0-4]\[0-9]|1\[0-9]\[0-9]|\[1-9]?\[0-9])$)|(^(?:(?:25\[0-5]|2\[0-4]\[0-9]|1\[0-9]\[0-9]|\[1-9]?\[0-9])\\.){3}(?:25\[0-5]|2\[0-4]\[0-9]|1\[0-9]\[0-9]|\[1-9]?\[0-9])\\s\*\\-\\s\*(?:(?:25\[0-5]|2\[0-4]\[0-9]|1\[0-9]\[0-9]|\[1-9]?\[0-9])\\.){3}(?:25\[0-5]|2\[0-4]\[0-9]|1\[0-9]\[0-9]|\[1-9]?\[0-9])$)/

 

IP range with sub mask

/(^(?:(?:25\[0-5]|2\[0-4]\[0-9]|1\[0-9]\[0-9]|\[1-9]?\[0-9])\\.){3}(?:25\[0-5]|2\[0-4]\[0-9]|1\[0-9]\[0-9]|\[1-9]?\[0-9])(?:/(3\[0-2]|2\[0-9]|1\[0-9]|\[1-9]))?$)|(^(?:(?:25\[0-5]|2\[0-4]\[0-9]|1\[0-9]\[0-9]|\[1-9]?\[0-9])\\.){3}(?:25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