Recently encountered in a website download can not download more than two files at the same time, in order to facilitate the download I used the Java Parsing web page source to download files, which used the regular expression, send a simple regular expression example.
Public classPatterntest { Public Static voidMain (string[] args) {String teststring= "; //complies with Name= ' Baidu ' <a> tags.String patternstring = "<\\s*[a| A] ([^>]*) [i| i][d| d]\\s*[=]\\s*[' |\ ' (Baidu) [' |\ '] (. *?) > "; Pattern Pattern=pattern.compile (patternstring, Pattern.dotall); Matcher Ma=Pattern.matcher (teststring); while(Ma.find ()) {System.out.println (Ma.group ()); } }}
The goal is to extract the <a> tag that satisfies id= ' Baidu ' in the webpage. The following explains what patternstring means:
\\s* a space between multiple spaces,< and A is also legal
([^>]*) multiple non-> strings
(.*?) Match as short a string as possible
Java Regular Expressions use