| |

VerySource

 Forgot password?
 Register
Search
View: 715|Reply: 2

Ask a simple question (regular)

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-16 10:30:01
| Show all posts |Read mode
How to determine the regular expression for a string with a length of no less than 6 digits?
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-12-16 11:45:01
| Show all posts
Any words are fine?

[\s\S]{6,}
Reply

Use magic Report

0

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-12-16 12:00:01
| Show all posts
Regular expression matching Chinese characters: [\u4e00-\u9fa5]
Comment: Matching Chinese is really a headache, with this expression it is easy to handle

Match double-byte characters (including Chinese characters): [^\x00-\xff]
Comment: Can be used to calculate the length of a string (a double-byte character counts as 2, ASCII character counts as 1)

Regular expression matching blank lines:\n\s*\r
Comment: Can be used to delete blank lines

Regular expression matching HTML tags: <(\S*?)[^>]*>.*?|<.*? />
Commentary: The version circulating on the Internet is too bad, the above one can only match part, and it is still helpless for complex nested tags

Regular expression matching the first and last blank characters: ^\s*|\s*$
Comment: It can be used to delete the blank characters at the beginning and end of the line (including spaces, tabs, form feeds, etc.), a very useful expression

Regular expression matching the email address:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
Comment: very useful for form validation

Regular expression to match the URL: [a-zA-z]+://[^\s]*
Commentary: The functions of the versions circulating on the Internet are very limited, and the above one can basically meet the needs

Whether the matching account is legal (beginning with a letter, allowing 5-16 bytes, allowing alphanumeric underscores): ^[a-zA-Z][a-zA-Z0-9_]{4,15}$
Comment: very useful for form validation

Match domestic phone numbers:\d{3}-\d{8}|\d{4}-\d{7}
Commentary: The matching form is like 0511-4405222 or 021-87888822

Match QQ number: [1-9][0-9]{4,}
Commentary: Tencent QQ number starts from 10000

Match Chinese postal code: [1-9]\d{5}(?!\d)
Commentary: Chinese postal code is 6 digits

Match ID:\d{15}|\d{18}
Commentary: China’s ID card is 15 or 18 digits

Match ip address:\d+\.\d+\.\d+\.\d+
Commentary: Useful when extracting IP address

Match a specific number:
^[1-9]\d*$    //Match a positive integer
^-[1-9]\d*$   //match negative integer
^-?[1-9]\d*$   //match integer
^[1-9]\d*|0$  //Match a non-negative integer (positive integer + 0)
^-[1-9]\d*|0$   //Match a non-positive integer (negative integer + 0)
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$   //match positive floating point numbers
^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$  //match negative floating point numbers
^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$  //match floating point number
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$   //Match a non-negative floating point number (positive floating point number + 0)
^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$  //matches non-positive floating-point numbers (negative floating-point numbers + 0)
Commentary: Useful when dealing with large amounts of data, pay attention to corrections in specific applications

Match a specific string:
^[A-Za-z]+$  //matches a string of 26 English letters
^[A-Z]+$  //matches a string of 26 uppercase English letters
^[a-z]+$  //Matches a string of 26 lowercase English letters
^[A-Za-z0-9]+$  //matches a string of numbers and 26 English letters
^\w+$  //matches a string consisting of numbers, 26 English letters or underscores
Commentary: some of the most basic and commonly used expressions


Email: [_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+ $
Or: w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*

Regular expression matching Chinese characters: [u4e00-u9fa5]
Match double-byte characters (including Chinese characters): [^x00-xff]
Regular expression matching blank lines: n[s| ]*r
Regular expression matching HTML tags: /<(.*)>.*|<(.*) />/
Regular expression matching the leading and trailing spaces: (^s*)|(s*$)
Match ip address:\d+\.\d+\.\d+\.\d+

Regular expression to match URL: ^[a-zA-z]+://(w+(-w+)*)(.(w+(-w+)*))*(?S*)?$
Whether the matching account is legal (beginning with a letter, allowing 5-16 bytes, allowing alphanumeric underscores): ^[a-zA-Z][a-zA-Z0-9_]{4,15}$
Match domestic phone numbers: (d{3}-|d{4}-)?(d{8}|d{7})?
Match ID:\d{15}|\d{18}
Match Tencent QQ number: ^[1-9]*[1-9][0-9]*$
Regular expression matching Chinese characters: [\u4e00-\u9fa5]
Match double-byte characters (including Chinese characters): [^\x00-\xff]
Regular expression matching blank lines:\n[\s| ]*\r
Regular expression matching HTML tags: /<(.*)>.*<\/\1>|<(.*)\/>/
Regular expression matching the leading and trailing spaces: (^\s*)|(\s*$) (trim function like vbscript)
Regular expression matching the email address:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
The regular expression that matches the URL: http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list