Java Regular Expression backup and java Regular Expression
Record the regular expressions used for testing in the project.
1,
Rule: 4-30 characters, numbers include "-", and "_" special characters
Regular Expression: ^ [0-_ a-zA-Z] {4, 30} $
2,
Rule: 6-20 characters, including at least two types of letters and numbers, and case sensitive
Regular: ^ (?! [A-zA-Z] + $ )(?! [0-9] + $) [a-zA-Z0-9] {6, 20} $
3,
Rule: integer multiple of 100
Regular Expression: ^ [1-9] [0-9] * 0 {2} $
4. Mobile phone number
Rule: the first digit is 1, 11 digits in total
Regular: ^ 1 \ d {10} $
Rule: 11 digits
Regular: ^ \ d {11} $
5. Non-empty judgment
Rule: enter a value
Regular: ^ [^ \ s] + $
6,
Rule: 8-20 characters can contain numbers, letters, underscores, and punctuation marks. It must contain numbers and letters and cannot contain Chinese or fullwidth characters.
Regular: ^ (?! [A-zA-Z] + $ )(?! [0-9] + $) [a-zA-Z1-9 \ u0000-\ u00FF] {} $
7,
Rule: a maximum of 14 digits cannot be 0 (a maximum of 3 digits after the decimal point)
Regular :(?! ^ 0 $ )(?! ^ [0] {2 ,})(?! ^ 0 [1-9] + )(?! ^ 0 \. [0] * $) ^ \ d {1, 10} (\. \ d {1, 3 })? $
8,
Rule: cannot contain decimal places
Regular :(?! ^ 0 * $) ^ \ d {} $ | ^ [0-9 {} (, [0-9 {3 }) {0, 4 }$ | ^ [0-9 {1, 3} (, [0-9 {3}) {0, 3} $
9,
Rule: cannot be less than 0.01 (up to two decimal places after the decimal point)
Regular :(?! ^ 0 $ )(?! ^ [0] {2 ,})(?! ^ 0 [1-9] + )(?! ^ 0 \. [0] * $) ^ ([1-9] + [0-9] *) | 0) (\. \ d {1, 2 })? $
10,
Rule: an integer greater than or equal to 100
Regular Expression: ^ [1-9] + [0-9] + [0-9] + $
11,
Rule: a maximum of 14 digits (a maximum of 2 digits after the decimal point) can be 0
Regular :(?! ^ [0] {2 ,})(?! ^ 0 [1-9] + )(?! ^ \. [0] * $) ^ \ d {1, 11} (\. \ d {1, 2 })? $
You are welcome to add and discuss it.
JAVA Regular Expression Code
\ S {6, 18}
The following are common regular expressions that can help you.
Size = 12px] 1. ^ \ D + $ // match a non-negative integer (positive integer + 0)
2. ^ [0-9] * [1-9] [0-9] * $ // match a positive integer
3. ^ (-\ D +) | (0 +) $ // match a non-positive integer (negative integer + 0)
4. ^-[0-9] * [1-9] [0-9] * $ // match a negative integer
5. ^ -? \ D + $ // match the integer
6. ^ \ D + (\. \ d + )? $ // Match non-negative floating point number (Positive floating point number + 0)
7. ^ ([0-9] + \. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ // matches the Positive floating point number
8. ^ (-\ D + (\. \ d + )?) | (0 + (\. 0 + )?)) $ // Match a non-Positive floating point number (negative floating point number + 0)
9. ^ (-([0-9] + \. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ // matches a negative floating point number.
10. ^ (-? \ D +) (\. \ d + )? $ // Match floating point numbers
11. ^ [A-Za-z] + $ // match A string consisting of 26 English letters
12. ^ [A-Z] + $ // match a string consisting of 26 uppercase letters
13. ^ [A-z] + $ // match a string consisting of 26 lowercase letters
14. ^ [A-Za-z0-9] + $ // match a string consisting of digits and 26 letters
15. ^ \ W + $ // match a string consisting of digits, 26 English letters, or underscores
16. ^ [\ W-] + (\. [\ w-] +) * @ [\ w-] + (\. [\ w-] +) + $ // match the email address
17. ^ [A-zA-z] +: // match (\ w + (-\ w + )*)(\. (\ w + (-\ w + )*))*(\? \ S *)? $ // Match the url
18. Regular Expression matching Chinese characters: [\ u4e00-\ u9fa5]
19. Match double-byte characters (including Chinese characters): [^ \ x00-\ xff]
20. Application: Calculate the length of a string (two-byte length Meter 2, ASCII character meter 1)
String. prototype. len = function () {return this. replace ([^ \ x00-\ xff]/g, "aa"). length ;}
21. Regular Expression for matching empty rows: \ n [\ s |] * \ r
22. Regular Expressions matching HTML tags:/<(. *)>. * <\/\ 1> | <(. *) \/>/
23. Regular Expression matching spaces at the beginning and end: (^ \ s *) | (\ s * $)... remaining full text>
Java Regular Expression
^ And $ are used to match the start and end of the string respectively. The following are examples:
"^ The": must start with a "The" string;
"Of despair $": the end must contain a string of "of despair;
So,
"^ Abc $": a string that must start with abc and end with abc. In fact, only abc matches.
"Notice": match a string containing notice.
You can see that if you do not use the two characters we mentioned (the last example), that is, the pattern (Regular Expression) can appear anywhere in the string to be tested, you didn't lock him to either side.
Next, let's talk about '*', '+', and '? ',
They are used to indicate the number or sequence of occurrences of a character. They represent:
"Zero or more" is equivalent to {0 ,},
"One or more" is equivalent to {1 ,},
"Zero or one." is equivalent to {0, 1}. Here are some examples:
"AB *": it is synonymous with AB {0,}. It matches a string starting with a and followed by 0 or N B ("a", "AB ", "abbb", etc );
"AB +": it is synonymous with AB {1,}. It is the same as the above, but there must be at least one B ("AB", "abbb", etc .);
"AB? ": It is synonymous with AB {0, 1} and can have no or only one B;
"? B + $ ": match the string ending with one or zero a plus more than one B.
Key points: '*', '+', and '? 'Only the character before it.
You can also limit the number of characters in braces, such
"AB {2}": requires that a be followed by two B (one cannot be less) ("abb ");
"AB {2,}": requires that there must be two or more B (such as "abb", "abbbb", etc.) after .);
"AB {3, 5}": requires 2-5 B ("abbb", "abbbb", or "abbbbb") after ").
Now we can put a few characters in parentheses, for example:
"A (bc) *": match a with 0 or a "bc ";
"A (bc) {}": one to five "bc ."
There is also a character '│', which is equivalent to the OR operation:
"Hi │ hello": Match string containing "hi" or "hello;
"(B │ cd) ef": matched with "bef ...... remaining full text>