Date
Dec. 22nd, 2024
 
2024年 11月 22日

Post: Useful RegEx

Useful RegEx

Published 12:09 Sep 20, 2015.

Created by @ezra. Categorized in #Technology, and tagged as #RegEx.

Source format: Markdown

Table of Content

Hex Value

/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/

匹配示例:

#a3c113

错误示例:

#4d82h4

HTML Tag

/^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/

匹配示例:

<a href="{{ site.url }}/">Meniny+</a>

错误示例:

<img src="img.jpg" ⌥="Some image>" />

IP Address

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

匹配示例:

123.45.67.89

错误示例:

256.45.67.89

URL

/^(https?:\/\/)?([\dA-Za-z\.-]+)\.([A-Za-z\.]{2,6})([\/\w \.-]*)*\/?$/

匹配示例:

{{ site.url }}/something

错误示例:

https://google.com/some/file!!.html

E-mail

/^([A-Za-z0-9_\.-]+)@([\dA-Za-z\.-]+)\.([A-Za-z\.]{2,6})$/

匹配示例:

[email protected]

错误示例:

[email protected]
Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
开发、设计与写作皆为所长。
热爱苹果、钟情色彩。
随时恭候 垂询