Java-11.4 Regular Expression (2)-basic syntax

Source: Internet
Author: User

Java-11.4 Regular Expression (2)-basic syntax

This section briefly introduces the basic syntax of regular expressions.

Our goal is not to write the most complex expressions, but to write the expressions that can complete tasks.

1. Character

 

Character Meaning
\ T Tab
\ N Line feed
\ R Enter
\ F Form feed
\ E Escape
\ Xhh Hexadecimal
\ Uhhhh Unicode hexadecimal

 

2. character classes

 

Character class Meaning
. Any character
[Abc] Any character containing abc
[^ Abc] Does not contain any characters of abc
[A-zA-z] Uppercase and lowercase letters of a-z
[Abc [ijk] Same as a | B | c | I | j | k (union)
[A-z & [ijk] Only ijk characters (intersection)
\ S Blank space (space, line feed, page feed, tab)
\ S Non-blank character [^ \ s]
\ D Number
\ D Non-numeric
\ W Word character [a-zA-z0-9]
\ W Non-word characters

 

3. boundary operator

 

Symbol Meaning
^ Start
$ End
\ B Word boundary
\ B Non-word boundary
\ G Last match ended

 

4. logic processing

 

XY X follows y.
X | Y X or y
(X) Capture Group

 

 

5. Create a regular expression

 

package com.ray.ch11;public class Test {public static void main(String[] args) {String a = "ddd012";for (String pattern : new String[] { "^[a-z]+[0-9]+$", "\\d+", "-?\\a+" }) {System.out.println(a.matches(pattern));}}}

Output:

 

True
False
False

 

Summary: This section describes the simple Syntax of regular expressions and how to create regular expressions in java.

 

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.