In regular expressions, matching any character may actually cause many problems on the Internet, but you can study it more. Today, I want to use a regular expression in Java to obtain any character in a piece of text. Therefore, you can write the following matching rules at will:
(.*)
After the result is run, the text after the line break cannot be obtained. So I checked the manual and found that in the regular expression, "." (dot symbol) matches all characters except the linefeed "\ n. At the same time, there is another sentence in the manual: to match any character including '\ n', please use a pattern like' [. \ n. So I modified the regular expression matching rules as follows:
([. \ N] *) of course, if it is written directly in a java program, you need to change it to ([. \ n] *)
The result is that the program is run again and no content can be obtained. I was puzzled and changed it to the following rules:
([. | \ N] *) and ([\ n.] *)
The result still does not work, and nothing can be obtained. It seems that the dot and line break are busy ~
Then I checked the Internet. although I didn't find out what the above rule was, I found a solution. after a try, I could indeed match any character including line breaks, the following are the correct regular expression matching rules:
([\ S \ S] *)
You can also use "([\ d \ D] *)" and "([\ w \ W.
In a text file, this expression can match all English letters.
/[-~] /
This expression can match all non-English characters (such as Chinese)
/[^-~] /
/Is used in VI. you do not need it in editplus or program/
For more articles about how to use regular expressions to match any character (including line breaks), refer to PHP!