By using regular expressions to represent text search parameters, some dynamically changing string matching, such as changing time, can be cleverly completed. Therefore, we have collected the "Boolean Education Regular Expression Video Tutorial", hoping to help everyone better understand regular expressions.
## Course playback address: http://www.php .cn/course/281.html
The teacher’s teaching style:
The more difficult point in this video is greedy and non-greedy:
#1. What are greedy and non-greedy in regular expressions? Greedy matching For example:String str="abcaxc"; Patter p="ab*c";
import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegularTest { public static void main(String[] arg){ String text="(content:\"rcpt to root\";pcre:\"word\";)"; String rule1="content:\".+\""; //贪婪模式 String rule2="content:\".+?\""; //非贪婪模式 System.out.println("文本:"+text); System.out.println("贪婪模式:"+rule1); Pattern p1 =Pattern.compile(rule1); Matcher m1 = p1.matcher(text); while(m1.find()){ System.out.println("匹配结果:"+m1.group(0)); } System.out.println("非贪婪模式:"+rule2); Pattern p2 =Pattern.compile(rule2); Matcher m2 = p2.matcher(text); while(m2.find()){ System.out.println("匹配结果:"+m2.group(0)); } } }
Here we also recommend downloading source code resources: //m.sbmmt.com/xiazai /code/2132
The above is the detailed content of Boolean Education Regular Expression Video Tutorial. For more information, please follow other related articles on the PHP Chinese website!