search
HomeJavajavaTutorialCommonly used regular expressions in java

"^/d+$" //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

"^-?/d+$" //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 float Point number

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

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

"^[A-Z]+$" // A string composed of 26 uppercase English letters

"^[a-z]+$" // A string consisting of 26 lowercase English letters

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

"^/w+$" //A string consisting of numbers, 26 English 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

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

"( d+-)?(d{4}-?d{7}|d{3}-?d{8}|^d{7,8})(-d+)?" //Phone number

"^(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 address

regular expression matching Chinese characters: [/u4e00-/u9fa5]

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

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

Regular expression matching HTML tags:/.*|/

Regular expression matching leading and trailing spaces: (^/s*)|(/s*$)

Regular expression matching email addresses: /w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*

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

Is the matching account legal (starting with a letter, 5-16 bytes allowed, alphanumeric underscores allowed): ^[a-zA-Z] [a-zA-Z0-9_]{4,15}$

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

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

metacharacters and their regular expressions Behavior in context:

/ Marks the next character as a special character, or a literal character, or a backreference, or an octal escape character.

^ Matches the beginning 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 preceding subexpression zero or more times.

+ Matches the preceding subexpression one or more times. + is equivalent to {1,}.

? Matches the preceding subexpression zero or one time. ? Equivalent to {0,1}.

{n} n is a non-negative integer that matches a certain number of n times.

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

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

? When this character immediately follows any of the other qualifiers (*, +, ?, {n}, {n,}, {n,m}), the matching pattern is non-greedy. Non-greedy mode matches as little of the searched string as possible, while the default greedy mode matches as much of the searched string as possible.

. Matches any single character except "/n". To match any character including '/n', use a pattern like '[./n]'.

(pattern) Match pattern and get this match.

(?:pattern) matches pattern but does not obtain the matching result, which means that this is a non-acquisition match and is not stored for later use.

(?=pattern) Forward lookup, match the search string at the beginning of any string matching pattern. This is a non-fetch match, that is, the match does not need to be fetched for later use.

(?!pattern) Negative lookup, opposite to (?=pattern)

x|y matches x or y.

[xyz] character set.

[^xyz] Negative value character set.

[a-z] Character range, matches any character within the specified range.

[^a-z] Negative character range, matches any character that is not within the specified range.

/b matches a word boundary, which refers to the position between a word and a space.

/B matches non-word boundaries.

/cx matches the control character specified by x.

/d matches a numeric character. Equivalent to [0-9].

/D matches a non-numeric character. Equivalent to [^0-9].

/f matches a form feed character. Equivalent to /x0c and /cL.

/n matches a newline character. Equivalent to /x0a and /cJ.

/r matches a carriage return character. Equivalent to /x0d and /cM.

/s matches any whitespace character, including spaces, tabs, form feeds, etc. Equivalent to [/f/n/r/t/v].

/S matches any non-whitespace character. Equivalent to [^ /f/n/r/t/v].

/t matches a tab character. Equivalent to /x09 and /cI.

/v matches a vertical tab character. Equivalent to /x0b and /cK.

/w matches any word character including an underscore. Equivalent to '[A-Za-z0-9_]'.

/W matches any non-word character. Equivalent to '[^A-Za-z0-9_]'.

/xn matches n, where n is the hexadecimal escape value. The hexadecimal escape value must be exactly two digits long.

/num matches num, where num is a positive integer. A reference to the match obtained.

/n identifies an octal escape value or a backreference. If /n is preceded by at least n fetched subexpressions, n is a backreference. Otherwise, if n is an octal number (0-7), then n is an octal escape value.

/nm Identifies an octal escape value or a backreference. If /nm is preceded by at least nm fetched subexpressions, nm is a backreference. If /nm is preceded by at least n gets, then n is a backreference followed by the literal m. If none of the previous conditions are true, then /nm matches the octal escape value nm if n and m are both octal digits (0-7).

/nml If n is an octal digit (0-3), and m and l are both octal digits (0-7), then matches the octal escape value nml.

/un matches n, where n is a Unicode character represented by four hexadecimal digits.

Regular expression to match Chinese characters: [u4e00-u9fa5]

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

Match Regular expression for empty lines: n[s| ]*r

Regular expression for matching HTML tags: /.*|/

Regular expression matching leading and trailing spaces: (^s*)|(s*$)

Regular expression matching email address: w+([-+.]w+)*@ w+([-.]w+)*.w+([-.]w+)*

Regular expression matching URL: http://([w-]+.)+[w-] +(/[w- ./?%&=]*)?

Use regular expressions to limit the input content of the text box in the web form:

Use regular expressions to limit only input Chinese: onkeyup="value=value.replace(/[^u4E00-u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^ u4E00-u9FA5]/g,''))"

Use regular expressions to limit the input of only full-width characters: onkeyup="value=value.replace(/[^uFF00-uFFFF]/g,'' )" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^uFF00-uFFFF]/g,''))"

Use regular expressions to limit Only numbers can be entered: onkeyup="value=value.replace(/[^d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[ ^d]/g,''))"

Use regular expressions to limit input to numbers and English only: onkeyup="value=value.replace(/[W]/g,'') "onbeforepaste ="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))"

 ********** *************************************************** ******************************************

Only numbers can be entered : "^[0-9]*$".

Only n-digit numbers can be entered: "^/d{n}$".

You can only enter a number with at least n digits: "^/d{n,}$".

Only m~n digits can be entered:. "^/d{m,n}$"

Only numbers starting with zero and non-zero can be entered: "^(0|[1-9][0-9]*)$".

Only positive real numbers with two decimal places can be entered: "^[0-9]+(.[0-9]{2})?$".

Only positive real numbers with 1 to 3 decimal places can be entered: "^[0-9]+(.[0-9]{1,3})?$".

Only non-zero positive integers can be entered: "^/+?[1-9][0-9]*$".

Only non-zero negative integers can be entered: "^/-[1-9][]0-9"*$.

Only characters with a length of 3 can be entered: "^.{3}$".

Only a string consisting of 26 English letters can be entered: "^[A-Za-z]+$".

Only a string consisting of 26 uppercase English letters can be entered: "^[A-Z]+$".

Only a string consisting of 26 lowercase English letters can be entered: "^[a-z]+$".

Only a string consisting of numbers and 26 English letters can be entered: "^[A-Za-z0-9]+$".

Only a string consisting of numbers and 26 English letters can be entered A string composed of English letters or underscores: "^/w+$".

Verify user password: "^[a-zA-Z]/w{5,17}$" The correct format is: starting with a letter, the length is between 6 and 18, and can only contain characters and numbers. and underline.

Verify whether it contains characters such as ^%&',;=?$/": "[^%&',;=?$/x22]+".

Only Chinese characters can be entered : "^[/u4e00-/u9fa5]{0,}$"

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

Verify InternetURL: "^http://([/w-]+/.)+[/w-]+ (/[/w-./?%&=]*)?$".

Verification phone number: "^(/(/d{3,4}-)|/d{3.4}-)?/d{7,8}$" The correct format is: "XXX-XXXXXXX", " XXXX-XXXXXXXX", "XXX-XXXXXXX", "XXX-XXXXXXXX", "XXXXXXX" and "XXXXXXXX".

Verify ID number (15 or 18 digits): "^/d{15}|/d{18}$".

Verify the 12 months of a year: "^(0?[1-9]|1[0-2])$" The correct format is: "01"~"09" and "1"~ "12".

Verify the 31 days of a month: "^((0?[1-9])|((1|2)[0-9])|30|31)$"The correct format is;" 01"~"09" and "1"~"31".

For more articles related to common regular expressions in Java, please pay attention to the PHP Chinese website!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Top 4 JavaScript Frameworks in 2025: React, Angular, Vue, SvelteTop 4 JavaScript Frameworks in 2025: React, Angular, Vue, SvelteMar 07, 2025 pm 06:09 PM

This article analyzes the top four JavaScript frameworks (React, Angular, Vue, Svelte) in 2025, comparing their performance, scalability, and future prospects. While all remain dominant due to strong communities and ecosystems, their relative popul

How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?Mar 17, 2025 pm 05:44 PM

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

Node.js 20: Key Performance Boosts and New FeaturesNode.js 20: Key Performance Boosts and New FeaturesMar 07, 2025 pm 06:12 PM

Node.js 20 significantly enhances performance via V8 engine improvements, notably faster garbage collection and I/O. New features include better WebAssembly support and refined debugging tools, boosting developer productivity and application speed.

How does Java's classloading mechanism work, including different classloaders and their delegation models?How does Java's classloading mechanism work, including different classloaders and their delegation models?Mar 17, 2025 pm 05:35 PM

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa

Spring Boot SnakeYAML 2.0 CVE-2022-1471 Issue FixedSpring Boot SnakeYAML 2.0 CVE-2022-1471 Issue FixedMar 07, 2025 pm 05:52 PM

This article addresses the CVE-2022-1471 vulnerability in SnakeYAML, a critical flaw allowing remote code execution. It details how upgrading Spring Boot applications to SnakeYAML 1.33 or later mitigates this risk, emphasizing that dependency updat

Iceberg: The Future of Data Lake TablesIceberg: The Future of Data Lake TablesMar 07, 2025 pm 06:31 PM

Iceberg, an open table format for large analytical datasets, improves data lake performance and scalability. It addresses limitations of Parquet/ORC through internal metadata management, enabling efficient schema evolution, time travel, concurrent w

How can I implement functional programming techniques in Java?How can I implement functional programming techniques in Java?Mar 11, 2025 pm 05:51 PM

This article explores integrating functional programming into Java using lambda expressions, Streams API, method references, and Optional. It highlights benefits like improved code readability and maintainability through conciseness and immutability

How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?Mar 17, 2025 pm 05:46 PM

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!