How to make Regular expression into non-greedy?

I’m using jQuery. I have a string with a block of special characters (begin and end). I want get the text from that special characters block. I used a regular expression object for in-string finding. But how can I tell jQuery to find multiple results when have two special character or more? My HTML: <div … Read more

Greedy vs. Reluctant vs. Possessive Qualifiers

I found this tutorial on regular expressions and while I intuitively understand what “greedy”, “reluctant” and “possessive” qualifiers do, there seems to be a serious hole in my understanding. Specifically, in the following example: Enter your regex: .*foo // Greedy qualifier Enter input string to search: xfooxxxxxxfoo I found the text “xfooxxxxxxfoo” starting at index … Read more

How can I write a regex which matches non greedy? [duplicate]

This question already has answers here: What do ‘lazy’ and ‘greedy’ mean in the context of regular expressions? (12 answers) How do I match any character across multiple lines in a regular expression? (25 answers) What is the difference between .*? and .* regular expressions? (3 answers) RegEx: Smallest possible match or nongreedy match (3 … Read more

Non greedy (reluctant) regex matching in sed?

I’m trying to use sed to clean up lines of URLs to extract just the domain. So from: http://www.suepearson.co.uk/product/174/71/3816/ I want: http://www.suepearson.co.uk/ (either with or without the trailing slash, it doesn’t matter) I have tried: sed ‘s|\(http:\/\/.*?\/\).*|\1|’ and (escaping the non-greedy quantifier) sed ‘s|\(http:\/\/.*\?\/\).*|\1|’ but I can not seem to get the non-greedy quantifier (?) … Read more

How can I make my match non greedy in vim?

I have a big HTML file that has lots of markup that looks like this: <p class=”MsoNormal” style=”margin: 0in 0in 0pt;”> <span style=”font-size: small; font-family: Times New Roman;”>stuff here</span> </p> I’m trying to do a Vim search-and-replace to get rid of all class=”” and style=”” but I’m having trouble making the match ungreedy. My first … Read more

What do ‘lazy’ and ‘greedy’ mean in the context of regular expressions?

What are these two terms in an understandable way? 12 s 12 Greedy will consume as much as possible. From http://www.regular-expressions.info/repeat.html we see the example of trying to match HTML tags with <.+>. Suppose you have the following: <em>Hello World</em> You may think that <.+> (. means any non newline character and + means one … Read more