regex-greedy

Why non-greedy quantifier sometimes doesn't work in Oracle regex?

微笑、不失礼 提交于 2019-11-27 23:26:54
IMO, this query should return A=1,B=2, SELECT regexp_substr('A=1,B=2,C=3,', '.*B=.*?,') as A_and_B FROM dual But it returns whole string A=1,B=2,C=3, instead. Why? UPD: Oracle 10.2+ required to use Perl-style metacharacters in regular expressions. UPD2: More clear form of my question (to avoid questions about Oracle version and availability of Perl-style regex extension): Why ON THE SAME SYSTEM non-greedy quantifier sometimes works as expected and sometimes doesn't? This works correctly: regexp_substr('A=1,B=2,C=3,', 'B=.*?,') This doesn't work: regexp_substr('A=1,B=2,C=3,', '.*B=.*?,') fiddle

How to do a non-greedy match in grep?

旧城冷巷雨未停 提交于 2019-11-27 10:09:53
I want to grep the shortest match and the pattern should be something like: <car ... model=BMW ...> ... ... ... </car> ... means any character and the input is multiple lines. You're looking for a non-greedy (or lazy) match. To get a non-greedy match in regular expressions you need to use the modifier ? after the quantifier. For example you can change .* to .*? . By default grep doesn't support non-greedy modifiers, but you can use grep -P to use the Perl syntax. John Smith Actualy the .*? only works in perl . I am not sure what the equivalent grep extended regexp syntax would be. Fortunately

How can I make my match non greedy in vim?

北城余情 提交于 2019-11-27 02:28:15
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 attempt was this %s/style=".*?"//g but Vim doesn't seem to like the ? . Unfortunately removing the ? makes the match too greedy. How can I make my match ungreedy? Instead of .* use .\{-} . %s/style=".\{-}"//g Also, see :help non-greedy Non greedy search

Question marks in regular expressions

丶灬走出姿态 提交于 2019-11-27 01:01:48
问题 I'm reading the regular expressions reference and I'm thinking about ? and ?? characters. Could you explain me with some examples their usefulness? I don't understand them enough. thank you 回答1: The key difference between ? and ?? concerns their laziness . ?? is lazy, ? is not. Let's say you want to search for the word "car" in a body of text, but you don't want to be restricted to just the singular "car"; you also want to match against the plural "cars". Here's an example sentence: I own

Regex credit card number tests

非 Y 不嫁゛ 提交于 2019-11-26 15:08:24
I'm testing one application where Regex pattern match credit card then such numbers should be highlighted. I'm using site http://regexpal.com/ to create test credit credit card numbers for my testing. my requirement is to have valid credit card numbers which can have "-" and/or "," between them.I was not successful to build such a number as when i test it using the site http://regexpal.com . I need few credit numbers with scenarios below valid credit card number which can have "-" between any digit. valid credit card number which can have "," between any digit. valid credit card number which

How to make Regular expression into non-greedy?

情到浓时终转凉″ 提交于 2019-11-26 11:37:29
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 nhất Phố Wall mới chỉ bắt đầu. </div> </div> and my JavaScript code: $(document).ready(function() { var

How can I make my match non greedy in vim?

筅森魡賤 提交于 2019-11-26 10:04:19
问题 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 attempt was this %s/style=\".*?\"//g but Vim doesn\'t seem to like the ? . Unfortunately removing the ? makes the match too greedy. How can

How to capture multiple repeated groups?

删除回忆录丶 提交于 2019-11-26 08:42:56
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 results somehow, so that I can use them?) UPDATE: I don't want to use split . I just need to now how to capture all

Regex credit card number tests

♀尐吖头ヾ 提交于 2019-11-26 05:55:36
问题 I\'m testing one application where Regex pattern match credit card then such numbers should be highlighted. I\'m using site http://regexpal.com/ to create test credit credit card numbers for my testing. my requirement is to have valid credit card numbers which can have \"-\" and/or \",\" between them.I was not successful to build such a number as when i test it using the site http://regexpal.com. I need few credit numbers with scenarios below valid credit card number which can have \"-\"

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

早过忘川 提交于 2019-11-26 03:16:50
问题 This question already has answers here : How do I match any character across multiple lines in a regular expression? (23 answers) Closed 3 months ago . I need help about regular expression matching with non-greedy option. The match pattern is: <img\\s.*> The text to match is: <html> <img src=\"test\"> abc <img src=\"a\" src=\'a\' a=b> </html> I test on http://regexpal.com This expression matches all text from <img to last > . I need it to match with the first encountered > after the initial