ITeye博客

Regular Expression: Greedy and Non-Greedy Quantification

standalone · 2011-04-12 11:25 · perl · 非技术 · Markdown

  1 my $string = '"hello there", said Pooh, "how are you today?". I said "brilliant!".';
  2 print "$string\n";
  3 $string =~ s/('|")(.*?)\1/$1.uc($2).$1/ge;
  4 print "$string\n";

 

I want to change letters in ' or '' to be uppercase. Without the ? the result will not be correct. Note that * is greedy and ? is not greedy.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。