The regular expression of Java se four: get

Source: Internet
Author: User
Tags java se

/** *  * @author Zen Johnny * @date April 29, 2018 PM 4:51:08 * */package Demo.regex;import Java.util.regex.matcher;import J Ava.util.regex.pattern;public class Regexgetdemo {public static void Getdemo (string string, string regex) {//step1: Encapsulates a rule into an object, pattern pattern = pattern.compile (regex),//STEP2: Associate a regular object with the string to extract, get a match (engine) object Matcher Matcher = Pattern.matcher (string); while (Matcher.find ()) {//constantly using the regular engine to find objects that conform to regular expressions, found: true; not found: FalseSystem.out.println (" Start: "+ matcher.start () +" word: "+ matcher.group () +" End: "+ matcher.end ());//Returns the currently found substring and returns the beginning of its word start () and End Interval End ( )}}public static void Main (String args[]) {//To extract more than 3 words in a row//hint: \b: word boundary; \b Non-word boundary string string = "Ming Tian Jiu Yao Fang J IA la,da jia~ "; String regex = "\\b[a-za-z]{3,}\\b"; Getdemo (String,regex);/*mingtianjiuyaofangjiajia   */}}

  

The regular expression of Java se four: get

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.