-- Start
我们已经知道了在正常情况下点号(.)是不能匹配换行符的,为了使点号能够匹配换行符,我们不得不使用工具提供的单行匹配模式。令人高兴的是,我们并非只有一种选择,通常排除型字符组是可以匹配换行符的,我们可以在需要点号匹配换行符的时候采用排除型字符组来替代。
#!/usr/bin/perl my $testText = "I love reg\nular expressions."; if($testText =~ m/reg[^ ]ular/) { print "finds the word."; } else { print "cannot find the word."; }
public static void main(String[] args) { String testText = "I love reg\nular expressions."; String regExp = "reg[^ ]ular"; Pattern p = Pattern.compile(regExp); Matcher m = p.matcher(testText); if (m.find()) { System.out.println("finds the word."); } else { System.out.println("cannot find the word."); } }
--更多参见:正则表达式精萃
-- 声 明:转载请注明出处
-- Last Updated on 2012-05-08
-- Written by ShangBo on 2012-05-08
-- End