regex-greedy

How to capture multiple repeated groups?

好久不见. 提交于 2019-11-26 02:37:23
问题 I need to capture multiple groups of the same pattern. Suppose, I have a following string: HELLO,THERE,WORLD And I\'ve written a following pattern ^(?:([A-Z]+),?)+$ What I want it to do is, capture every single word, so that Group 1 is : \"HELLO\", Group 2 is \"THERE\" and Group 3 is \"WORLD\" What my regex is actually capturing only the last one, which is \"WORLD\". I\'m testing my regular expression here and I want to use it with Swift (maybe there\'s a way in Swift to get intermediate

How to make Regular expression into non-greedy?

霸气de小男生 提交于 2019-11-26 02:17:39
问题 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 id=\"container\"> <div id=\"textcontainer\"> Cuộc chiến pháp lý giữa [|cơ thử|nghiệm|] thị trường [|test2|đây là test lần 2|] chứng khoán [|Mỹ|day la nuoc my|] và ngân hàng đầu tư quyền lực

Python non-greedy regexes

雨燕双飞 提交于 2019-11-26 00:48:30
问题 How do I make a python regex like \"(.*)\" such that, given \"a (b) c (d) e\" python matches \"b\" instead of \"b) c (d\"? I know that I can use \"[^)]\" instead of \".\", but I\'m looking for a more general solution that keeps my regex a little cleaner. Is there any way to tell python \"hey, match this as soon as possible\"? 回答1: You seek the all-powerful '*?' http://docs.python.org/3/howto/regex.html#greedy-versus-non-greedy the non-greedy qualifiers *?, +?, ??, or {m,n}? [...] match as

Greedy vs. Reluctant vs. Possessive Quantifiers

半腔热情 提交于 2019-11-25 22:56:24
问题 I found this excellent tutorial on regular expressions and while I intuitively understand what \"greedy\", \"reluctant\" and \"possessive\" quantifiers do, there seems to be a serious hole in my understanding. Specifically, in the following example: Enter your regex: .*foo // greedy quantifier Enter input string to search: xfooxxxxxxfoo I found the text \"xfooxxxxxxfoo\" starting at index 0 and ending at index 13. Enter your regex: .*?foo // reluctant quantifier Enter input string to search:

What is the difference between .*? and .* regular expressions?

荒凉一梦 提交于 2019-11-25 22:19:53
问题 I\'m trying to split up a string into two parts using regex. The string is formatted as follows: text to extract<number> I\'ve been using (.*?)< and <(.*?)> which work fine but after reading into regex a little, I\'ve just started to wonder why I need the ? in the expressions. I\'ve only done it like that after finding them through this site so I\'m not exactly sure what the difference is. 回答1: It is the difference between greedy and non-greedy quantifiers. Consider the input 101000000000100

Python non-greedy regexes

点点圈 提交于 2019-11-25 22:17:32
How do I make a python regex like "(.*)" such that, given "a (b) c (d) e" python matches "b" instead of "b) c (d"? I know that I can use "[^)]" instead of ".", but I'm looking for a more general solution that keeps my regex a little cleaner. Is there any way to tell python "hey, match this as soon as possible"? Trey Stout You seek the all-powerful '*?' http://docs.python.org/3/howto/regex.html#greedy-versus-non-greedy the non-greedy qualifiers *?, +?, ??, or {m,n}? [...] match as little text as possible. >>> x = "a (b) c (d) e" >>> re.search(r"\(.*\)", x).group() '(b) c (d)' >>> re.search(r"\(

What do &#39;lazy&#39; and &#39;greedy&#39; mean in the context of regular expressions?

这一生的挚爱 提交于 2019-11-25 21:35:15
问题 Could someone explain these two terms in an understandable way? 回答1: 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 or more ) would only match the <em> and the </em> , when in reality it will be very greedy, and go from the first < to the last > . This means it