banner
ximalaya

ximalaya

这里是openkava 的blog,关注程序开发的一切技术。 ZZ 表示转载的文章,如涉及版权,请和我联系删除。 在这里你可以看到关于以下技术的文章: 移动开发技术,ANDROID ,IOS,WINDOWS PHONE平台开发,企业ERP开发,动态脚本PYTHON ,OPENGL ES 3D技术,游戏开发技术,HTML5 ,JAVASCRIPT ,MYSQL,AMAZON EC2 ,GOOGLE GAE ,GOOGLE CLOUD SQL 等 。 本站发展历程: 2010年,正式把所有的blog移到这里,租用godaddy的空间,记录生活和工作上的一些心得。 下面是关于我的个人介绍,写在这里权当凑字数啦。 职业:软件开发,开发经验6年,管理经验3年; 工作上使用的技术:C#, SQL SERVER 个人使用的技术:PYTHON,PHP, CSS, JAVA ,ANDROID ,object-c 等等 联系我请发邮件:<a href="http://blog.openkava.com/openkava@gmail.png"><img class="alignnone size-full wp-image-96" title="邮箱" src="http://blog.openkava.com/openkava@gmail.png" alt="" width="174" height="24" /></a>

Regular expressions are used for string processing.

Regular expressions are used for string processing, form validation, and other occasions, and are practical and efficient. Here are some commonly used expressions collected here for future reference.
Regular expression for matching Chinese characters: [\u4e00-\u9fa5]
Note: Matching Chinese characters can be a headache, but with this expression, it becomes easier.

Regular expression for matching double-byte characters (including Chinese characters): [^\x00-\xff]
Note: It can be used to calculate the length of a string (a double-byte character counts as 2, ASCII characters count as 1).

Regular expression for matching blank lines: \n\s*\r
Note: It can be used to delete blank lines.

Regular expression for matching HTML tags: <(\S*?)[^>]>.?</\1>|<.*? />
Note: The versions circulating online are terrible, and this one can only match part of it, still powerless for complex nested tags.

Regular expression for matching leading and trailing whitespace characters: ^\s*|\s*$
Note: It can be used to delete leading and trailing whitespace characters (including spaces, tabs, page breaks, etc.), a very useful expression.

Regular expression for matching email addresses: \w+([-+.]\w+)@\w+([-.]\w+).\w+([-.]\w+)*
Note: Very useful for form validation.

Regular expression for matching URLs: [a-zA-z]+://[^\s]*
Note: The versions circulating online have limited functionality, and this one can basically meet the requirements.

Regular expression for matching valid accounts (starting with a letter, allowing 5-16 bytes, allowing alphanumeric and underscore characters): ^[a-zA-Z][a-zA-Z0-9_]{4,15}$
Note: Very useful for form validation.

Regular expression for matching domestic phone numbers: \d{3}-\d{8}|\d{4}-\d{7}
Note: Matches the format like 0511-4405222 or 021-87888822.

Regular expression for matching Tencent QQ numbers: [1-9][0-9]{4,}
Note: Tencent QQ numbers start from 10000.

Regular expression for matching Chinese postal codes: [1-9]\d{5}(?!\d)
Note: Chinese postal codes are 6-digit numbers.

Regular expression for matching ID cards: \d{15}|\d{18}
Note: Chinese ID cards are 15 or 18 digits.

Regular expression for matching IP addresses: \d+.\d+.\d+.\d+
Note: Useful for extracting IP addresses.

Regular expression for matching specific numbers:
^[1-9]\d*$   // Matches positive integers
^-[1-9]\d*$   // Matches negative integers
^-?[1-9]\d*$   // Matches integers
^[1-9]\d*|0$  // Matches non-negative integers (positive integers + 0)
^-[1-9]\d*|0$   // Matches non-positive integers (negative integers + 0)
^[1-9]\d*.\d*|0.\d*[1-9]\d*$   // Matches positive floating-point numbers
^-([1-9]\d*.\d*|0.\d*[1-9]\d*)$  // Matches negative floating-point numbers
^-?([1-9]\d*.\d*|0.\d*[1-9]\d*|0?.0+|0)$  // Matches floating-point numbers
^[1-9]\d*.\d*|0.\d*[1-9]\d*|0?.0+|0$   // Matches non-negative floating-point numbers (positive floating-point numbers + 0)
^(-([1-9]\d*.\d*|0.\d*[1-9]\d*))|0?.0+|0$  // Matches non-positive floating-point numbers (negative floating-point numbers + 0)
Note: Useful for handling large amounts of data, pay attention to adjustments when applying.

Regular expression for matching specific strings:
^[A-Za-z]+$  // Matches strings consisting of 26 English letters
^[A-Z]+$  // Matches strings consisting of 26 uppercase English letters
^[a-z]+$  // Matches strings consisting of 26 lowercase English letters
^[A-Za-z0-9]+$  // Matches strings consisting of numbers and 26 English letters
^\w+$  // Matches strings consisting of numbers, 26 English letters, or underscores.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.