Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Regular expressions commonly used in java

Shulou Source: shulou.com Published: 2022-06-02 04:59:24 11月10日 Update

This article introduces the knowledge of "regular expressions commonly used in java". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

"^ / positive $" / / non-negative integer (positive integer + 0)

"^ [0-9] * [1-9] [0-9] * $" / / positive integer

"^ (- / d+) | (0 +) $" / / non-positive integer (negative integer + 0)

"^-[0-9] * [1-9] [0-9] * $" / / negative integer

"^ -? / dumped $" / / Integer

"^ / d + (/. / d +)? $" / / non-negative floating point number (positive floating point number + 0)

"^ (([0-9] + /. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * /. [0-9] +) | ([0-9] * [1-9] [0-9] *)) $" / / positive floating point number

"^ ((- / d+ (/. / d+)?) | (0 + (/ .0 +)?) $" / / non-positive floating point number (negative floating point number + 0)

"^ (- ([0-9] + /. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * /. [0-9] +) | ([0-9] * [1-9] [0-9] *)) $" / / negative floating point number

"^ (-? / d +) (/. / d +)? $" / / floating point number

"^ [A-Za-z] + $" / / A string of 26 letters

"^ [Amurz] + $" / / A string of 26 English letters in uppercase

A string of 26 lowercase letters consisting of "^ [amurz] + $" / /

"^ [A-Za-z0-9] + $" / / A string of numbers and 26 letters

A string of numbers, 26 letters, or underscores

"^ [/ w -] + (/ .[ / w -] +) * @ [/ w -] + (/. [/ w -] +) + $" / / email address

"^ [a-zA-z] +: / / (/ w + (- / w +) *) (/. (/ w + (- / w +) *)) * (/? / S*)? $" / / url

/ ^ (d {2} | d {4})-(0 ([1-9] {1})) | (1 [1 | 2]))-([0-2] ([1-9] {1})) | (3 [0 | 1])) $/ year-month-day

/ ^ ((0 ([1-9] {1})) | (1 [1 | 2])) / ([0-2] ([1-9] {1})) | (3 [0 | 1])) / (d {2} | d {4}) $/ month / day / year

"^ ([wmere.] +) @ ([[0-9] {1Mague 3}. [0-9] {1pr 3}. [0-9] {1pr 3}.) | (([w -] +.)) ([a-zA-Z] {2jue 4} | [0-9] {1Mague 3}) (]?) $" / / Emil

"(dwells -)? (d {4} -? d {7} | d {3} -? d {8} | ^ d {7je 8}) (- d +)? / / phone number

"^ (d {1 1dd 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1 IP 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1 recorder 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1pm 2} | 1dd | 2 [0-4] d | 25 [0-5])

Regular expression that matches Chinese characters: [/ u4e00-/u9fa5]

Match double-byte characters (including Chinese characters): [^ / x00-/xff]

Regular expression that matches blank lines: / n [/ s |] * / r

Regular expression that matches the HTML tag: /. * | /

Regular expression that matches leading and trailing spaces: (^ / s*) | (/ sworn $)

Regular expression that matches the Email address: / w + ([- +.] / w +) * @ / w + ([-.] / w +) * /. / w + ([-.] / w +) *

Regular expression that matches the URL URL: ^ [a-zA-z] +: / / (/ / w+ (- / / w+) *) (/ /. (/ / w+ (- / / w+) *) * (/ /? / / S*)? $

Whether the matching account is legal (5-16 bytes are allowed at the beginning of the letter, and alphanumeric underscores are allowed): ^ [a-zA-Z] [a-zA-Z0-9 _] {4j 15} $

Match domestic phone number: (/ d {3}-| / d {4} -)? (/ d {8} | / d {7})?

Match Tencent QQ number: ^ [1-9] * [1-9] [0-9] * $

Metacharacters and their behavior in the context of regular expressions:

Marks the next character as a special character, or a literal character, or a backward reference, or an octal escape character.

^ matches the starting position of the input string. If the Multiline property of the RegExp object is set, ^ also matches the position after'/ n'or'/ r'.

$matches the end of the input string. If the Multiline property of the RegExp object is set, $also matches the position before'/ n'or'/ r'.

* matches the previous subexpression zero or more times.

+ matches the previous subexpression one or more times. + is equivalent to {1,}.

? Matches the previous subexpression zero or once. ? It is equivalent to {0jue 1}.

{n} n is a non-negative integer that matches a determined n times.

{n,} n is a non-negative integer that matches at least n times.

{n ·m} m} m and n are non-negative integers, where n

Tags: Characters expressions inputs numbers regular strings letters integers equivalents English octal escape validation points limits underscores positions words addresses formats Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Linux NVidia Docker Microsoft