---
title: "Regular Expression: Greedy and Non-Greedy Quantification"
author: "standalone"
date: "2011-04-12T11:25:50Z"
tags: []
categories: ["非技术"]
slug: "regular-expression-greedy-and-non-greedy-quantification"
draft: false
lastmod: "2011-04-12T11:25:50Z"
id: 998663
url: "https://standalone.iteye.com/blog/998663"
---

```
  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.