首页 > 运维 > linux运维 > 正文

运维必备,正则表达式超全速查手册,赶快收藏!

发布: 2023-08-02 17:45:23
转载
1494 人浏览过
^[0-9]*$n位的数字:^\d{n}$至少n位的数字:^\d{n,}$m-n位的数字:^\d{m,n}$零和非零开头的数字:^(0|[1-9][0-9]*)$非零开头的最多带两位小数的数字:^([1-9][0-9]*)+(.[0-9]{1,2})?$带1-2位小数的正数或负数:^(\-)?\d+(\.\d{1,2})?$正数、负数、和小数:^(\-|\+)?\d+(\.\d+)?$有两位小数的正实数:^[0-9]+(.[0-9]{2})?$有1~3位小数的正实数:^[0-9]+(.[0-9]{1,3})?$非零的正整数:^[1-9]\d*$ 或 ^([1-9][0-9]*){1,3}$ 或 ^\+?[1-9][0-9]*$非零的负整数:^\-[1-9][]0-9"*$ 或 ^-[1-9]\d*$
登录后复制

非负整数<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding :0px;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:换行:换行!重要;字体大小:16px;溢出换行:换行:换行!重要;行高:25px;">^d+$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^d+$</span> 或 <span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[1-9]d*|0$</span> 或 

<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;最大宽度:100%;框大小:边框框!重要;自动换行:断字!重要;字体大小:16px;溢出换行:断字!重要;行高:25px;” >^[1-9]d*|0$🎜🎜

非正整数<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px ;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:换行:换行!重要;字体大小:16px;溢出换行:换行!重要;行-高度:25px;">^-[1-9]d*|0$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^-[1-9]d*|0$</span> 或 <span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^((-d+)|(0+))$</span> 或 <span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding :0px;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:换行:换行!重要;字体大小:16px;溢出换行:换行:换行!重要;行高:25px;">^((-d+)|(0+))$🎜</span>🎜

非负浮点数<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:换行:换行!重要;字体大小:16px;溢出换行:换行:换行!重要;行-height: 25px;">^d+(.d+)?$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^d+(.d+)?$</span> 或 <span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0$</span> 或 

<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:换行:换行!重要;字体大小:16px;溢出换行:换行!重要;行高: 25px;">^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0$🎜</span>🎜

非正浮点数<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:换行:换行!重要;字体大小:16px;溢出换行:换行:换行!重要;行-高度:25px;">^((-d+(.d+)?)|(0+(.0+)?))$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^((-d+(.d+)?)|(0+(.0+)?))$</span> 或 <span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^(-([1-9]d*.d*|0.d*[1-9]d*))|0?.0+|0$</span> 或 

<span mp-original-font-size="“16”mp-original-line-" height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size :16px;溢出换行:断字!重要;行高:25px;">^(-([1-9]d*.d*|0.d*[1-9]d*))| 0?.0+|0$🎜</span>🎜

正浮点<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px ;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:换行:换行!重要;字体大小:16px;溢出换行:换行!重要;行-高度:25px;">^[1-9]d*.d*|0.d*[1-9]d*$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[1-9]d*.d*|0.d*[1-9]d*$</span> 或 <span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*))$</span> 或 

<span mp-original-font-size="“16”mp-original-line-height" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;溢出换行:断字!重要;行高:25px;">^(([0-9]+.[0-9]*[1-9][0-9]*)|( [0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*))$🎜代码>🎜<p mp-original-font-size="17" mp-original-line-height="27" style='margin: 0px 0px 1.2em !important;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;clear: both;min-height: 1em;caret-color: rgb(34, 34, 34);color: rgb(34, 34, 34);font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 17px;font-style: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;text-indent: 0px;text-transform: none;white-space: normal;word-spacing: 0px;-webkit-text-size-adjust: auto;-webkit-text-stroke-width: 0px;text-decoration: none;font-variant-ligatures: normal;orphans: 2;widows: 2;background-color: rgb(255, 255, 255);text-align: left;overflow-wrap: break-word !important;line-height: 27px;'><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;line-height: 25px;"><strong mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;overflow-wrap: break-word !important;font-size: 16px;line-height: 25px;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;overflow-wrap: break-word !important;font-size: 16px;line-height: 25px;">负浮点数</span></strong><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;overflow-wrap: break-word !important;font-size: 16px;line-height: 25px;">:</span></span><code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3 em;轮廓:0px;最大宽度:100%;字体大小:14.45px;字体系列:Consolas、Inconsolata、Courier、等宽字体;空白:预换行;边框宽度:1px;边框样式:固体;边框颜色: rgb(234, 234, 234);背景颜色: rgb(248, 248, 248);边框半径: 3px;显示: 内联;行高: 23px;框大小: border-框!重要;overflow-wrap:break-word!重要;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px ;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:换行:换行!重要;字体大小:16px;溢出换行:换行!重要;行-高度:25px;">^-([1-9]d*.d*|0.d*[1-9]d*)$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^-([1-9]d*.d*|0.d*[1-9]d*)$</span> 或 <span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^(-(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*)))$</span> 或 

<span mp-original-font-size="“16”mp-original-" line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap:break-word !important;font -size: 16px;overflow-wrap: 断词!重要;行高: 25px;">^(-(([0-9]+.[0-9]*[1-9][0-9 ]*)|([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*) ))$🎜</span>🎜

浮点数<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:换行:换行!重要;字体大小:16px;溢出换行:换行:换行!重要;行高: 25px;">^(-?d+)(.d+)?$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^(-?d+)(.d+)?$</span> 或 <span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^-?([1-9]d*.d*|0.d*[1-9]d*|0?.0+|0)$</span> 或 

<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:换行:换行!重要;字体大小:16px;溢出换行:换行:换行!重要;行-高度:25px;">^-?([1-9]d*.d*|0.d*[1-9]d*|0?.0+|0)$🎜</span>🎜

运维必备,正则表达式超全速查手册,赶快收藏!

二、校验字符的表达式

汉字<span mp-original-font-size="16" mp-original-line-height="25 " style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow -wrap: 换行!重要;行高:25px;">^[u4e00-u9fa5]{0,}$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[u4e00-u9fa5]{0,}$</span>

英文和数字<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px ;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:换行:换行!重要;字体大小:16px;溢出换行:换行!重要;行-高度:25px;">^[A-Za-z0-9]+$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[A-Za-z0-9]+$</span> 或 <span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[A-Za-z0-9]{4,40}$</span> 或 

<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding :0px;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:换行:换行!重要;字体大小:16px;溢出换行:换行:换行!重要;行高:25px;">^[A-Za-z0-9]{4,40}$🎜</span>🎜

长度为3-20的所有字符<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;填充:0px;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:换行:换行!重要;字体大小:16px;溢出换行:换行!重要;行高: 25px;">^.{3,20}$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^.{3,20}$</span>

由26个英文字母组成的字符串<span mp-original-font-size="16" mp-original-line-height="25" style="margin :0px;填充:0px;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:break-word!重要;字体大小:16px;溢出换行:break-字!重要;行高:25px;">^[A-Za-z]+$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[A-Za-z]+$</span>

由26个大写英文字母组成的字符串<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[A-Z]+$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[A-Z]+$</span>

另外,搜索公众号Java后端栈后台回复“私活”,获取一份惊喜礼包。

由26个小写英文字母组成的字符串<span mp-original-font-size="16" mp-original-line-height="25" style="边距:0px;填充:0px;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:break-word!重要;字体大小:16px;溢出换行:break -word !重要;行高: 25px;">^[a-z]+$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[a-z]+$</span>

由数字和26个英文字母组成的字符串<span mp-original-font-size="16" mp-original-line-height="25" style='“边距:0px;填充:0px;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:断字!重要;字体大小:16px;溢出换行:断词!重要;行高:25px;"'>^[A-Za-z0-9]+$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[A-Za-z0-9]+$</span>

由数字、26个英文字母或者下划线组成的字符串<span mp-original-font-size="“16”mp-original-line-height" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap:break-word !important;font-size: 16px;overflow-换行:换行!重要;行高:25px;">^w+$ 或 ^w{3,20}<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^w+$ 或 ^w{3,20}</span>

中文、中文、数字包括下划线<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px ;填充:0px;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:换行:换行!重要;字体大小:16px;溢出换行:换行!重要;行高: 25px;">^[u4E00-u9FA5A-Za-z0-9_]+$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[u4E00-u9FA5A-Za-z0-9_]+$</span>

中文、中文、数字但不包括下划线等符号<span mp-original-font-size="16" mp-original-line-height="25" style='“边距:0px;填充:0px;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:断字!重要;字体大小:16px;溢出换行:断词!重要;行高:25px;"'>^[u4E00-u9FA5A-Za-z0-9]+$<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[u4E00-u9FA5A-Za-z0-9]+$</span> 或 <span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[u4E00-u9FA5A-Za-z0-9]{2,20}$</span> 或 

<span mp-original-font-size="16" mp-original-line-height=" 25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;溢出换行:换行!重要;行高:25px;">^[u4E00-u9FA5A-Za-z0-9]{2,20}$🎜</span>🎜

可以输入含有<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;最大宽度:100%;框大小:边框框!重要;自动换行:断字!重要;字体大小:16px;溢出换行:断字!重要;行高:25px ;">^%&',;=?$"<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^%&',;=?$"</span> 等字符:<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">[^%&',;=?$x22]+</span> 等字符:

<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;轮廓:0px;最大宽度:100%;框大小:边框框!重要;自动换行:换行:换行!重要;字体大小:16px;溢出换行:换行!重要;行高: 25px;">[^%&',;=?$x22]+🎜</span>🎜

禁止输入含有~的字符<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">[^~x22]+</span>[^~x22]+

🎜

其它

.*匹配除 \n 以外的任何字符。/[\u4E00-\u9FA5]/ 汉字/[\uFF00-\uFFFF]/ 全角符号/[\u0000-\u00FF]/ 半角符号
登录后复制

三、特殊需求表达式

Email 地址<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$</span>

[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?
登录后复制
[a-zA-z]+://[^\s]* 或 ^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$
登录后复制
^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$
登录后复制

电话号码(“XXX-XXXXXXX”、”XXXX-XXXXXXXX”、”XXX-XXXXXXX”、”XXX-XXXXXXXX”、”XXXXXXX”和”XXXXXXXX):<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$</span>

国内电话号码(0511-4405222、021-87888822):<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">\d{3}-\d{8}|\d{4}-\d{7}</span>

身份证号码(15位、18位数字):<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^d{15}|d{18}$</span>^d{15}|d{18}$

🎜

短身份证号码(数字、字母x结尾):<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^([0-9]){7,18}(x|X)?</span>$ 或 <span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^d{8,18}|[0-9x]{8,18}|[0-9X]{8,18}?$</span>^([0-9]){7,18}(x|X)?

🎜$ 或 🎜 🎜^d{8,18}|[0-9x]{8,18}|[0-9X]{8,18}?$🎜🎜

帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[a-zA-Z][a-zA-Z0-9_]{4,15}$</span>

密码(以字母开头,长度在6~18之间,只能包含字母、数字和下划线):<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[a-zA-Z]w{5,17}$</span>^[a-zA-Z][a-zA-Z0-9_]{4,15}$

🎜🎜🎜密码(以字母开头,长度在6~18之间,只能包含字母、数字和下划线):🎜🎜^[a-zA-Z]w{5,17}$🎜🎜

强密码(必须包含大小写字母和数字的组合,不能使用特殊字符,长度在8-10之间):<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$</span>

日期格式:<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^d{4}-d{1,2}-d{1,2}</span>^(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$

🎜🎜🎜日期格式:🎜🎜^d{4}-d{1,2}-d{1,2}🎜🎜

一年的12个月(01~09和1~12):<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^(0?[1-9]|1[0-2])$</span>

一个月的31天(01~09和1~31):<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^((0?[1-9])|((1|2)[0-9])|30|31)$</span>^(0?[1-9]|1[0-2])$

🎜🎜🎜一个月的31天(01~09和1~31):🎜🎜^((0?[1-9])|((1|2)[0-9])|30|31)$🎜 🎜

钱的输入格式

有四种钱的表示形式我们可以接受:”10000.00” 和 “10,000.00”, 和没有 “分” 的 “10000” 和 “10,000”:<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[1-9][0-9]*$</span>^[1-9][0-9]*$

🎜

这表示任意一个不以0开头的数字,但是,这也意味着一个字符”0”不通过,所以我们采用下面的形式:<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^(0|[1-9][0-9]*)$</span>

一个0或者一个不以0开头的数字.我们还可以允许开头有一个负号:<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^(0|-?[1-9][0-9]*)$</span>^(0|[1-9][0-9]*)$

🎜🎜🎜一个0或者一个不以0开头的数字.我们还可以允许开头有一个负号:🎜🎜^(0|-?[1-9][0-9]*)$🎜🎜

4.这表示一个0或者一个可能为负的开头不为0的数字.让用户以0开头好了.把负号的也去掉,因为钱总不能是负的吧.下面我们要加的是说明可能的小数部分:<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[0-9]+(.[0-9]+)?$</span>

必须说明的是,小数点后面至少应该有1位数,所以”10.”是不通过的,但是 “10” 和 “10.2” 是通过的:<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[0-9]+(.[0-9]{2})?$</span>^[0-9]+(.[0-9]+)?$

🎜🎜🎜必须说明的是,小数点后面至少应该有1位数,所以”10.”是不通过的,但是 “10” 和 “10.2” 是通过的:🎜🎜^[0-9]+(.[0-9]{2})?$🎜🎜

这样我们规定小数点后面必须有两位,如果你认为太苛刻了,可以这样:<code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[0-9]+(.[0-9]{1,2})?$</span>^[0-9]+(.[0-9]{1,2})?$

🎜

这样就允许用户只写一位小数.下面我们该考虑数字中的 <code mp-original-font-size="14.449999809265137" mp-original-line-height="23" style="margin: 0px 0.15em;padding: 0px 0.3em;outline: 0px;max-width: 100%;font-size: 14.45px;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;line-height: 23px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">逗号</span> 了,我们可以这样:<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^[0-9]{1,3}(,[0-9]{3})*(.[0-9]{1,2})?$</span>逗号

🎜 了,我们可以这样:🎜🎜^[0-9]{1,3}(,[0-9]{3})*(.[0-9]{1,2})?$🎜🎜

1到3个数字,后面跟着任意个 逗号+3个数字,逗号成为可选,而不是必须:<span mp-original-font-size="16" mp-original-line-height="25" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 25px;">^([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(.[0-9]{1,2})?$</span>

备注:这就是最终结果了,别忘了+可以用*替代如果你觉得空字符串也可以接受的话(奇怪,为什么?)最后,别忘了在用函数时去掉去掉那个反
登录后复制

xml文件:^([a-zA-Z]+-?)+[a-zA-Z0-9]+\.[x|X][m|M][l|L]$

中文字符的正则表达式:[\u4e00-\u9fa5]

双字节字符:^x00-xff)

空白行的正则表达式:ns*r (可以用来删除空白行)

HTML标记的正则表达式:<(S?)[^>]>.?|<.? /> (网上流传的版本太糟糕,上面这个也仅仅能部分,对于复杂的嵌套标记依旧无能为力)

首尾空白字符的正则表达式:^s|s

) (可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式)


腾讯QQ号:[1-9][0-9]{4,}(腾讯QQ号从10000开始)

中国邮政编码:[1-9]d{5}(?!d)(中国邮政编码为6位数字)

IP地址:d+.d+.d+.d+(提取IP地址时有用)

IP地址:((?:(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d?\d))

牛逼啊!接私活必备的 N 个开源项目!赶快收藏吧
登录后复制

IP-v4地址:\b(?:(?: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]?)\b (提取IP地址时有用)

校验IP-v6地址:

(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))
登录后复制

子网掩码:

((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))
登录后复制

校验日期:

^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$(“yyyy-mm-dd“ 格式的日期校验,已考虑平闰年。)
登录后复制

抽取注释:<span mp-original-font-size="16" mp-original-line-height="28" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 28px;"><!--(.*?)--></span>

查找CSS属性:<span mp-original-font-size="16" mp-original-line-height="28" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 28px;">^\\s*[a-zA-Z\\-]+\\s*[:]{1}\\s[a-zA-Z0-9\\s.#]+[;]{1}</span>

提取页面超链接:<code mp-original-font-size="14" mp-original-line-height="24" style='margin: 0px 2px;padding: 2px 4px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 14px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;background-color: rgba(27, 31, 35, 0.0470588);font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(255, 93, 108);overflow-wrap: break-word !important;line-height: 24px;'><span mp-original-font-size="16" mp-original-line-height="28" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 28px;">(<a\s*(?!.*\brel=)[^>]*)(href="https?:\/\/)((?!(?:(?:www\.)?'.implode('|(?:www\.)?', $follow_list).'))[^" rel="external nofollow" ]+)"((?!.*\brel=)[^>]*)(?:[^>]*)></span>

提取网页图片:<span mp-original-font-size="16" mp-original-line-height="28" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 28px;">\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)</span>(]*)(href="https?:\/\/)((?!(?:(?:www\.)?'.implode('|(? :www\.)?', $follow_list).'))[^" rel="external nofollow" ]+)"((?!.*\brel=)[^>]*)(?:[^ >]*)>

🎜🎜🎜提取网页图片:🎜🎜\]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)🎜🎜

另外,搜索公众号GitHub猿后台回复“赚钱”,获取一份惊喜礼包。

提取网页颜色代码:<code mp-original-font-size="14" mp-original-line-height="24" style='margin: 0px 2px;padding: 2px 4px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 14px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;background-color: rgba(27, 31, 35, 0.0470588);font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(255, 93, 108);overflow-wrap: break-word !important;line-height: 24px;'><span mp-original-font-size="16" mp-original-line-height="28" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 28px;">^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$</span>^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$

🎜

文件扩展名效验:<code mp-original-font-size="14" mp-original-line-height="24" style='margin: 0px 2px;padding: 2px 4px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 14px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;background-color: rgba(27, 31, 35, 0.0470588);font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(255, 93, 108);overflow-wrap: break-word !important;line-height: 24px;'><span mp-original-font-size="16" mp-original-line-height="28" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 28px;">^([a-zA-Z]\:|\)\([^\]+\)*[^\/:*?"<>|]+\.txt(l)?$</span>

判断IE版本:<span mp-original-font-size="16" mp-original-line-height="28" style="margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;font-size: 16px;overflow-wrap: break-word !important;line-height: 28px;">^.*MSIE [5-8](?:\.[0-9]+)?(?!.*Trident\/[5-9]\.0).*$</span>^([a-zA-Z ]\:|\\)\\([^\\]+\\)*[^\/:*?"<>|]+\.txt(l)?$

🎜🎜 🎜判断IE版本:🎜🎜^.*MSIE [5-8]( ?:\.[0-9]+)?(?!.*三叉戟\/[5-9]\.0).*$🎜🎜


附表:

运维必备,正则表达式超全速查手册,赶快收藏!

运维必备,正则表达式超全速查手册,赶快收藏!

运维必备,正则表达式超全速查手册,赶快收藏!

运维必备,正则表达式超全速查手册,赶快收藏!

运维必备,正则表达式超全速查手册,赶快收藏!

运维必备,正则表达式超全速查手册,赶快收藏!

运维必备,正则表达式超全速查手册,赶快收藏!

运维必备,正则表达式超全速查手册,赶快收藏!

运维必备,正则表达式超全速查手册,赶快收藏!

运维必备,正则表达式超全速查手册,赶快收藏!

以上是运维必备,正则表达式超全速查手册,赶快收藏!的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:Linux中文社区
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!