Regular expression matches any character

It turns out that the "." In the regular expression represents any character other than the newline. If you really want to represent any character, you need to add the newline character, but after testing "[. \ N]" does not take effect, you can use it " \ s \ S "stands for all null characters + all non-null characters.
Note: In order to apply to java programs, the above expression has replaced slashes with double slashes.

package com.hgh.springcloud.feign;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TestYYQAndZFS {

    public static String Str = "营业";

    public static void main(String[] args) {
        Pattern pattern = Pattern.compile("[营][业][区]");

        String name1 = "营业";
        System.out.println("1:" + Pattern.matches("/*[营][业]/*",name1));

        String name2 = "11营业区";
        Matcher m = pattern.matcher(name2);

        System.out.println(m.find());
        //可行
        Pattern pattern2 = Pattern.compile(".*营业.*区.*");
        String name3 = "营业4354343fsdfsd区2233";
        Matcher m2 = pattern2.matcher(name3);
        System.out.println(m2.find());

        Pattern pattern4 = Pattern.compile("([\\s\\S]*)营业([\\s\\S]*)区([\\s\\S]*)");
        String name4 = "123123营业4354343fsdfsd区2233";
        Matcher m4 = pattern4.matcher(name3);
        System.out.println(m4.find());
    }
}

Published 331 original articles · 51 praises · 440,000 visits +

Guess you like

Origin blog.csdn.net/y41992910/article/details/103935667