1. 平时做网站经常要用正则表达式,下面是一些讲解和例子,仅供大家参考和修改使用:
2. "^\d+$" //非负整数(正整数 + 0)
3. "^[0-9]*[1-9][0-9]*$" //正整数
4. "^((-\d+)|(0+))$" //非正整数(负整数 + 0)
5. "^-[0-9]*[1-9][0-9]*$" //负整数
6. "^-?\d+$" //整数
7. "^\d+(\.\d+)?$" //非负浮点数(正浮点数 + 0)
8. "^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$" //正浮点数
9. "^((-\d+(\.\d+)?)|(0+(\.0+)?))$" //非正浮点数(负浮点数 + 0)
10. "^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$" //负浮点数
11. "^(-?\d+)(\.\d+)?$" //浮点数
12. "^[A-Za-z]+$" //由26个英文字母组成的字符串
13. "^[A-Z]+$" //由26个英文字母的大写组成的字符串
14. "^[a-z]+$" //由26个英文字母的小写组成的字符串
15. "^[A-Za-z0-9]+$" //由数字和26个英文字母组成的字符串
16. "^\w+$" //由数字、26个英文字母或者下划线组成的字符串
17. "^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$" //email地址
18. "^[a-zA-z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$" //url
19. /^(d{2}|d{4})-((0([1-9]{1}))|(1[1|2]))-(([0-2]([1-9]{1}))|(3[0|1]))$/ // 年-月-日
20. /^((0([1-9]{1}))|(1[1|2]))/(([0-2]([1-9]{1}))|(3[0|1]))/(d{2}|d{4})$/ // 月/日/年
21. "^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$" //Emil
22. /^((\+?[0-9]{2,4}\-[0-9]{3,4}\-)|([0-9]{3,4}\-))?([0-9]{7,8})(\-[0-9]+)?$/ //电话号码
23. "^(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5])$" //IP地址
24.
25. 匹配中文字符的正则表达式: [\u4e00-\u9fa5]
26. 匹配双字节字符(包括汉字在内):[^\x00-\xff]
27. 匹配空行的正则表达式:\n[\s| ]*\r
28. 匹配HTML标记的正则表达式:/.*|/
29. 匹配首尾空格的正则表达式:(^\s*)|(\s*$)
30. 匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
31. 匹配网址URL的正则表达式:^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$
32. 匹配帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
33. 匹配国内电话号码:(\d{3}-|\d{4}-)?(\d{8}|\d{7})?
34. 匹配腾讯QQ号:^[1-9]*[1-9][0-9]*$
35.
36.
37. 元字符及其在正则表达式上下文中的行为:
38.
39. \ 将下一个字符标记为一个特殊字符、或一个原义字符、或一个后向引用、或一个八进制转义符。
40.
41. ^ 匹配输入字符串的开始位置。如果设置了 RegExp 对象的Multiline 属性,^ 也匹配 ’\n’ 或 ’\r’ 之后的位置。
42.
43. $ 匹配输入字符串的结束位置。如果设置了 RegExp 对象的Multiline 属性,$ 也匹配 ’\n’ 或 ’\r’ 之前的位置。
44.
45. * 匹配前面的子表达式零次或多次。
46.
47. + 匹配前面的子表达式一次或多次。+ 等价于 {1,}。
48.
49. ? 匹配前面的子表达式零次或一次。? 等价于 {0,1}。
50.
51. {n} n 是一个非负整数,匹配确定的n 次。
52.
53. {n,} n 是一个非负整数,至少匹配n 次。
54.
55. {n,m} m 和 n 均为非负整数,其中n 56.
57. ? 当该字符紧跟在任何一个其他限制符 (*, +, ?, {n}, {n,}, {n,m}) 后面时,匹配模式是非贪婪的。非贪婪模式尽可能少的匹配所搜索的字符串,而默认的贪婪模式则尽可能多的匹配所搜索的字符串。
58.
59. . 匹配除 "\n" 之外的任何单个字符。要匹配包括 ’\n’ 在内的任何字符,请使用象 ’[.\n]’ 的模式。
60. (pattern) 匹配pattern 并获取这一匹配。
61.
62. (?:pattern) 匹配pattern 但不获取匹配结果,也就是说这是一个非获取匹配,不进行存储供以后使用。
63.
64. (?=pattern) 正向预查,在任何匹配 pattern 的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要获取供以后使用。
65.
66. (?!pattern) 负向预查,与(?=pattern)作用相反
67.
68. x|y 匹配 x 或 y。
69.
70. [xyz] 字符集合。
71.
72. [^xyz] 负值字符集合。
73.
74. [a-z] 字符范围,匹配指定范围内的任意字符。
75.
76. [^a-z] 负值字符范围,匹配任何不在指定范围内的任意字符。
77.
78. \b 匹配一个单词边界,也就是指单词和空格间的位置。
79.
80. \B 匹配非单词边界。
81.
82. \cx 匹配由x指明的控制字符。
83.
84. \d 匹配一个数字字符。等价于 [0-9]。
85.
86. \D 匹配一个非数字字符。等价于 [^0-9]。
87.
88. \f 匹配一个换页符。等价于 \x0c 和 \cL。
89.
90. \n 匹配一个换行符。等价于 \x0a 和 \cJ。
91.
92. \r 匹配一个回车符。等价于 \x0d 和 \cM。
93.
94. \s 匹配任何空白字符,包括空格、制表符、换页符等等。等价于[ \f\n\r\t\v]。
95.
96. \S 匹配任何非空白字符。等价于 [^ \f\n\r\t\v]。
97.
98. \t 匹配一个制表符。等价于 \x09 和 \cI。
99.
100. \v 匹配一个垂直制表符。等价于 \x0b 和 \cK。
101.
102. \w 匹配包括下划线的任何单词字符。等价于’[A-Za-z0-9_]’。
103.
104. \W 匹配任何非单词字符。等价于 ’[^A-Za-z0-9_]’。
105.
106. \xn 匹配 n,其中 n 为十六进制转义值。十六进制转义值必须为确定的两个数字长。
107.
108. \num 匹配 num,其中num是一个正整数。对所获取的匹配的引用。
109.
110. \n 标识一个八进制转义值或一个后向引用。如果 \n 之前至少 n 个获取的子表达式,则 n 为后向引用。否则,如果 n 为八进制数字 (0-7),则 n 为一个八进制转义值。
111.
112. \nm 标识一个八进制转义值或一个后向引用。如果 \nm 之前至少有is preceded by at least nm 个获取得子表达式,则 nm 为后向引用。如果 \nm 之前至少有 n 个获取,则 n 为一个后跟文字 m 的后向引用。如果前面的条件都不满足,若 n 和 m 均为八进制数字 (0-7),则 \nm 将匹配八进制转义值 nm。
113.
114. \nml 如果 n 为八进制数字 (0-3),且 m 和 l 均为八进制数字 (0-7),则匹配八进制转义值 nml。
115.
116. \un 匹配 n,其中 n 是一个用四个十六进制数字表示的Unicode字符。
117.
118. 匹配中文字符的正则表达式: [u4e00-u9fa5]
119.
120. 匹配双字节字符(包括汉字在内):[^x00-xff]
121.
122. 匹配空行的正则表达式:n[s| ]*r
123.
124. 匹配HTML标记的正则表达式:/.*1>|/
125.
126. 匹配首尾空格的正则表达式:(^s*)|(s*$)
127.
128. 匹配Email地址的正则表达式:w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*
129.
130. 匹配网址URL的正则表达式:http://([w-]+.)+[w-]+(/[w- ./?%&=]*)?
131.
132. 利用正则表达式限制网页表单里的文本框输入内容:
133.
134. 用 正则表达式限制只能输入中文:onkeyup="value=value.replace(/[^u4E00-u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^u4E00-u9FA5]/g,''))"
135.
136. 用正则表达式限制只能输入全角字符: onkeyup="value=value.replace(/[^uFF00-uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^uFF00-uFFFF]/g,''))"
137.
138. 用正则表达式限制只能输入数 字:onkeyup="value=value.replace(/[^d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))"
139.
140. 用正则表达式限制只能输入数字和英 文:onkeyup="value=value.replace(/[W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))"
141.
142. =========常用正则式
143.
144.
145.
146. 匹配中文字符的正则表达式: [\u4e00-\u9fa5]
147.
148. 匹配双字节字符(包括汉字在内):[^\x00-\xff]
149.
150. 匹配空行的正则表达式:\n[\s| ]*\r
151.
152. 匹配HTML标记的正则表达式:/.*|/
153.
154. 匹配首尾空格的正则表达式:(^\s*)|(\s*$)
155.
156. 匹配IP地址的正则表达式:/(\d+)\.(\d+)\.(\d+)\.(\d+)/g //
157.
158. 匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
159.
160. 匹配网址URL的正则表达式:http://(/[\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
161.
162. sql语句:^(select|drop|delete|create|update|insert).*$
163.
164. 1、非负整数:^\d+$
165.
166. 2、正整数:^[0-9]*[1-9][0-9]*$
167.
168. 3、非正整数:^((-\d+)|(0+))$
169.
170. 4、负整数:^-[0-9]*[1-9][0-9]*$
171.
172. 5、整数:^-?\d+$
173.
174. 6、非负浮点数:^\d+(\.\d+)?$
175.
176. 7、正浮点数:^((0-9)+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$
177.
178. 8、非正浮点数:^((-\d+\.\d+)?)|(0+(\.0+)?))$
179.
180. 9、负浮点数:^(-((正浮点数正则式)))$
181.
182. 10、英文字符串:^[A-Za-z]+$
183.
184. 11、英文大写串:^[A-Z]+$
185.
186. 12、英文小写串:^[a-z]+$
187.
188. 13、英文字符数字串:^[A-Za-z0-9]+$
189.
190. 14、英数字加下划线串:^\w+$
191.
192. 15、E-mail地址:^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$
193.
194. 16、URL:^[a-zA-Z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\s*)?$
195. 或:^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^\"\"])*$
196.
197. 17、邮政编码:^[1-9]\d{5}$
198.
199. 18、中文:^[\u0391-\uFFE5]+$
200.
201. 19、电话号码:^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$
202.
203. 20、手机号码:^((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$
204.
205. 21、双字节字符(包括汉字在内):^\x00-\xff
206.
207. 22、匹配首尾空格:(^\s*)|(\s*$)(像vbscript那样的trim函数)
208.
209. 23、匹配HTML标记:.*|
210.
211. 24、匹配空行:\n[\s| ]*\r
212.
213. 25、提取信息中的网络链接:(h|H)(r|R)(e|E)(f|F) *= *('|")?(\w|\\|\/|\.)+('|"| *|>)?
214.
215. 26、提取信息中的邮件地址:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
216.
217. 27、提取信息中的图片链接:(s|S)(r|R)(c|C) *= *('|")?(\w|\\|\/|\.)+('|"| *|>)?
218.
219. 28、提取信息中的IP地址:(\d+)\.(\d+)\.(\d+)\.(\d+)
220.
221. 29、提取信息中的中国手机号码:(86)*0*13\d{9}
222.
223. 30、提取信息中的中国固定电话号码:(\(\d{3,4}\)|\d{3,4}-|\s)?\d{8}
224.
225. 31、提取信息中的中国电话号码(包括移动和固定电话):(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}
226.
227. 32、提取信息中的中国邮政编码:[1-9]{1}(\d+){5}
228.
229. 33、提取信息中的浮点数(即小数):(-?\d*)\.?\d+
230.
231. 34、提取信息中的任何数字 :(-?\d*)(\.\d+)?
232.
233. 35、IP:(\d+)\.(\d+)\.(\d+)\.(\d+)
234.
235. 36、电话区号:/^0\d{2,3}$/
236.
237. 37、腾讯QQ号:^[1-9]*[1-9][0-9]*$
238.
239. 38、帐号(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
240.
241. 39、中文、英文、数字及下划线:^[\u4e00-\u9fa5_a-zA-Z0-9]+$

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor