A detailed explanation of Java Regular expression syntax _java

Source: Internet
Author: User

Shared Java Regular expression syntax and examples below

1, matching verification-Verify that the email is correct

public static void Main (string[] args) {
 //string
 str = "service@xsoftlab.net" to be validated;
 Mailbox validation Rule
 String regEx = [a-za-z_]{1,}[0-9]{0,}@ ([a-za-z0-9]-*) {1,}\\.) {1,3} [a-za-z\\-] {1,} ";
 Compile regular expression pattern
 = Pattern.compile (regEx);
 Ignores case writing/pattern
 Pat = pattern.compile (regEx, pattern.case_insensitive);
 Matcher Matcher = Pattern.matcher (str);
 Whether the string matches the regular expression
 Boolean rs = Matcher.matches ();
 System.out.println (RS);

2. Query character or string in string

public static void Main (string[] args) {
 //string
 str = "baike.xsoftlab.net" to be validated;
 Regular expression rule
 String regEx = "baike.*";
 Compile regular expression pattern
 = Pattern.compile (regEx);
 Ignores case writing/pattern
 Pat = pattern.compile (regEx, pattern.case_insensitive);
 Matcher Matcher = Pattern.matcher (str);
 Find out if there is a character/string in the string that matches the regular expression
 Boolean rs = Matcher.find ();
 System.out.println (RS);

3, regular expression of the common

4, Regular expression syntax

About Java Regular expression syntax and examples for everyone to introduce this, I hope to help you learn.

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.