0. Internet 1. Text 2. Graphics 3. System 4. File 5. Misc 6. Palm 7. OS X |
Grep is greedy; make it less so # While editing an HTML file in TextWrangler, I needed to find and replace all occurrences of: <span class="a">text</span>This regex: \<span class=\"a\"\>.*\<\/span\>returned results like: <span class="a">text</span><span class="b">more text</span>Using a non-greedy quantifier (the question mark) returned the desired results: \<span class=\"a\"\>.*?\<\/span\> UPDATE: Wikipedia has more on lazy quantification: "... modern regular expression tools allow a quantifier to be specified as lazy (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., <.*?>) ..." /mac | Apr 11, 2010 |
Categories
Blosxom Archive
2012: 5 4 3 2 1
2011: 12 11 10 9 8 7 6 5 4 3 2 1 2010: 12 11 10 9 8 7 6 5 4 3 2 1 2009: 12 11 10 9 8 7 6 5 4 3 2 1 2008: 12 11 10 9 8 7 6 5 4 3 2 1 2007: 12 11 10 9 8 7 6 5 4 3 2 1 2006: 12 11 10 9 8 7 6 5 4 3 2 1 2005: 12 11 10 Blogger Archive
Ezine Archive
|