Regular Expressions (J2SE Topic II) __ Regular expressions

Source: Internet
Author: User
Regular expressions

1, the regular expression is straightforward to deal with the string of sharp objects (for string matching).

2, about regular expressions in Java mainly used in the Java.lang.string,java.util.regex.pattern and java.util.regex.Matcher these three classes. Its writing mainly has the following two kinds:

A, string string = "Sssss";

String.matches (". *");/whether this string matches a regular expression in the form of ". *" If the match returns TRUE or vice versa.

b, pattern patterns = Pattern.compile (". *");//Generate a model class with a ". *" Regular expression model

Matcher Matcher = Pattern.matcher ("sssss");//generate a matching class

Matcher.matches ();//To match

Note: A method is more convenient than B, while B compares a provides more string matching methods.

3, regular expressions commonly-spoken characters meaning:

˙ represents any one character * indicating 0 or more repetitions

+ Represents the repetition of one or more times {}

[] represents a range of values () that represents the meaning of a group

。 Repeat 0 times or once

Note: The symbols for more regular expressions are explained in Java.utit.regex.Pattern.

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.