Regular expressions match any character (including line breaks)--Regular expressions
Source: Internet
Author: User
Today in Java, you want to use a regular expression to get any character in a paragraph of text. So it's very casual to write the following matching rules:
(.*)
After the results are run, the text after the wrapping cannot be obtained. Then I looked up the manual and found the regular expression, "." (dot notation) matches all characters except the newline character "\ n". At the same time, there is a word in the manual: to match any character including ' \ n ', use a pattern like ' [. \ n] '. So I modified the matching rule for the regular expression as follows:
([. \n]*), of course, if you write to a word directly in a Java program, you need to change to ([. \\n]*)
As a result, run the program again, and find out what content is not taken. I am baffled and revise it to the following rules:
([.| \n]*) and ([\ n.] *)
The result is still no, nothing can be obtained. It seems that the point symbol and the line Fu Yi Ober ~
Then the Internet to check, although did not find out what the above rules is where the problem, but found a solution, after a try, can indeed match including line-break characters, any character, the following is the correct regular expression matching rules:
([\s\s]*)
It can also be represented by "([\d\d]*)", "([\w\w]*)".
In a text file, this expression can match all the English
/[ -~]/
This expression can match all non-English (such as Chinese)
/[^ -~]/
/is used in VI. You don't need to be in a editplus or a program.
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.