Java regular expression content acquired in the middle of two characters

Regular expressions obtaining an intermediate value of the two strings

Directly on the code, it is not difficult.

    public  static  void main (String [] args) { 

        // content 
        String value = "fileNameCode -> _ AD2467524284sd234.json" ; 

        // matching rules 
        String REG = "_ \\ (*.?)." ; 
        Pattern pattern = Pattern .compile (REG); 

        // test content matching rule 
        Matcher Matcher = Pattern.matcher (value); 

        IF (matcher.find ()) {
             // contains two characters before and after the 
            System.out.println (matcher.group ());
             // does not contain two characters before and after the 
            System.out.println (Matcher.group (. 1 )); 
        } the else {
            System.out.println ( "not matched to the content ...." ); 
        } 
    }

 

Note: This requires: \\ so.

() -> mark a sub-expressions start and end position.

-> match newline \ n except outside of any single character.

* -> Matches the preceding subexpression zero or more times.

? -> sub-expression matching the front end of zero or one.

 

Guess you like

Origin www.cnblogs.com/oukele/p/11110680.html