Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A complete Collection of regular expressions commonly used in Java

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "A Collection of regular expressions commonly used in Java". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the regular expressions commonly used in Java.

Here are some regular expressions and regular validation expressions commonly used in our daily work.

Regular expressions related to numbers

Number: ^ [0-9] * $

N-digit fixed-length number: ^\ d {n} $

The number between mmurn digits: ^\ d {mrecom n} $

Zero and non-zero numbers: ^ (0 | [1-9] [0-9] *) $

A number with up to two decimal places at the beginning of a non-zero: ^ ([1-9] [0-9] *) + (. [0-9] {1J2})? $

Positive or negative numbers with 1-2 decimal places: ^ (\ -)?\ d + (\. D {1jin2})? $

Positive, negative, and decimal: ^ (\-|\ +)?\ d + (\.\ d +)? $

A positive real number with two decimal places: ^ [0-9] + (. [0-9] {2})? $

A positive real number with 1 to 3 decimal places: ^ [0-9] + (. [0-9] {1jue 3})? $

Positive integer: ^\ DX $or ^ [1-9]\ d* | 0 $

Negative integer: ^-[1-9]\ d* | 0$ or ^ ((-\ d+) | (0 +)) $

Positive floating point number: ^ [1-9]\ d *\.\ d * | 0\.\ d * [1-9]\ dfloat $or ^ (([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 numbers: ^-([1-9]\ d *\.\ d * | 0\.\ d * [1-9]\ d *) $or ^ (0-9) +. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] *. [0-9] +) | ([0-9] * [1-9] [0-9] *)) $

Floating point number: ^ (-?\ d +) (\.\ d +)? $or ^ -? ([1-9]\ d *.\ d * | 0.\ d * [1-9]\ d * | 0?\ .0 + | 0) $

Regular expressions related to characters

Chinese character: ^ [\ u4e00 -\ u9fa5] {0,} $

All characters with a length of 3-20: ^. {3pm 20} $

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

A string consisting of numbers, 26 letters, or underscores: ^\ w {3} 20} $or ^\ w

Chinese, English, numbers including underscore: ^ [\ u4E00 -\ u9FA5A-Za-z0-9] + $

Chinese, English, numbers but excluding underscores and other symbols: ^ [\ u4E00 -\ u9FA5A-Za-z0-9] + $or ^ [\ u4E00 -\ u9FA5A-Za-z0-9] {2jue 20} $

Whether the account is legal (starting with letters, allowing 5-16 bytes, allowing alphanumeric underscores): ^ [a-zA-Z] [a-zA-Z0-9 _] {4jue 15} $

Password (begins with a letter, is between 6 and 18 in length, and can only contain letters, numbers and underscores): ^ [a-zA-Z]\ w {5Magne17} $

Strong password (must contain a combination of uppercase and lowercase letters and numbers, cannot use special characters, length is between 8 and 10): ^ (? =. *\ d) (? =. * [Amurz]) (? =. * [Amurz]). {8jue 10} $

A regular expression in a fixed format

Email address: ^\ w + ([- +.]\ w +) * @\ w + ([-.]\ w +) *.\ w + ([-.]\ w +) * $

Domain name of the website: [a-zA-Z0-9] [- a-zA-Z0-9] {0a-zA-Z0 62} (/. [a-zA-Z0-9] [- a-zA-Z0-9] {0jue 62}) + /.

URL address: ^ http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$

Mobile number: ^ (13 [0-9] | 17 [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} $

Phone numbers ("XXX-XXXXXXX", "XXXX-XXXXXXXX", "XXX-XXXXXXX", "XXX-XXXXXXXX", "XXXXXXX" and "XXXXXXXX"): ^ (\ (\ d {3Magin4} -) |\ d {3.4} -)?\ d {7pc8} $

Domestic telephone number (0511-4405222, 021-87888822):\ d {3} -\ d {8} |\ d {4} -\ d {7}

ID card number (15 digits, 18 digits): ^\ d {15} |\ d {18} $

Date format: ^\ d {4} -\ d {1pc2} -\ d {1pc2}

12 months of the year (01 / 09 and 01 / 12): ^ (0? [1-9] | 1 [0-2]) $

31 days of a month (01 / 09 and 01 / 31): ^ (0? [1-9]) | (1 | 2) [0-9]) | 30 | 31) $

Tencent QQ number: [1-9] [0-9] {4 QQ 8} (Tencent QQ number starts from 10000 and currently has a maximum length of 10 digits)

China Postal Code: [1-9]\ d {5} (?!\ d) (China Postal Code is 6 digits)

IP address:\ d +\.\ d +\.\ d + (useful when extracting IP addresses)

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

At this point, I believe you have a deeper understanding of the regular expressions commonly used in Java, so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report