Regex expressions
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi All,
I'm preparing for the SCJP 1.6 exam and have some doubt in the page no:500 which is in exam watch in the K&B book . I dont understand. Please explain this concept.
I'm preparing for the SCJP 1.6 exam and have some doubt in the page no:500 which is in exam watch in the K&B book . I dont understand. Please explain this concept.
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Could you post what exactly it states ? I don't have the book at hand.
JDBCSupport - An easy to use, light-weight JDBC framework -
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
This should clear your doubts, I guess (I don't have a book):
http://java.sun.com/docs/books/tutorial/essential/regex/quant.html
http://java.sun.com/docs/books/tutorial/essential/regex/quant.html
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
posted 16 years ago
please post the question too....... apart from quoting the source.....
java RegEx "a?" "aba"....
here "?" is a greedy quantifier..... it always searches for ZERO or ONE(here) matches......
remember the rule "ALL THE GREEDY QUANTIFIERS CHECKS ONE INDEX PAST THE STRING TO FIND A MATCH"
so in case of "?" and "*" they wil always find a zero length match at the end(that is one index past the given string)
if you try the same with "?" quantifier, i suppose you will get the same answer.....
thanks friend....
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
jayalakshmi charugundla wrote:Hi All,
I'm preparing for the SCJP 1.6 exam and have some doubt in the page no:500 which is in exam watch in the K&B book . I dont understand. Please explain this concept.
please post the question too....... apart from quoting the source.....
java RegEx "a?" "aba"....
here "?" is a greedy quantifier..... it always searches for ZERO or ONE(here) matches......
remember the rule "ALL THE GREEDY QUANTIFIERS CHECKS ONE INDEX PAST THE STRING TO FIND A MATCH"
so in case of "?" and "*" they wil always find a zero length match at the end(that is one index past the given string)
if you try the same with "?" quantifier, i suppose you will get the same answer.....
thanks friend....
KARTHICK.C , SCJP6-93%
(Born to Win)
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi,
I too am having some trouble with Regular Expressions. For instance I ran the following regular expressions. I understand the result for (ab)* but when I switch from a greedy quantifier to a reluctant quantifier it finds nothing at each index and I am not able to understand why. Can someone please explain this to me?
Many thanks.
I too am having some trouble with Regular Expressions. For instance I ran the following regular expressions. I understand the result for (ab)* but when I switch from a greedy quantifier to a reluctant quantifier it finds nothing at each index and I am not able to understand why. Can someone please explain this to me?
Many thanks.
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Read "Differences Among Greedy, Reluctant, and Possessive Quantifiers" section in http://java.sun.com/docs/books/tutorial/essential/regex/quant.html
Steven Lennon
Greenhorn
Posts: 5
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi,
Thanks, I have been referring to that tutorial but still don't understand why the second regular expression didn't find an 'ab' match. A reluctant qualifier consumes the string one character at a time but I still thought it would find an 'ab' match.
Any help will be appreciated. Thanks.
Thanks, I have been referring to that tutorial but still don't understand why the second regular expression didn't find an 'ab' match. A reluctant qualifier consumes the string one character at a time but I still thought it would find an 'ab' match.
Any help will be appreciated. Thanks.
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Anybody can explain this?
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Steven Lennon
Greenhorn
Posts: 5
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi,
Thanks for prompting on this question. I still haven't been able to find an answer to explain this reg exp output. Either I am missing something really fundamental here or it is not the correct output for such an expression.
Thanks and Regards
Thanks for prompting on this question. I still haven't been able to find an answer to explain this reg exp output. Either I am missing something really fundamental here or it is not the correct output for such an expression.
Thanks and Regards
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
This is how I think it works (I've not read much about Regex so might be wrong)
Regex Engine's first priority is the overall success of the regex. Reluctant quantifiers try to match as less as possible. They'll only match more, if that can effect the overall success of the regular expression. Suppose your regex is a*?, and your input is aaaa, then it will try to match as less as possible so it'll result only in zero length matches. But if your regex is a*?b, and input is aaabaab, then you'll get aaab and aab as matches, this time a*? matched more because otherwise the whole regex would've failed. Since in the earlier case (a*? and aaaa), zero length matches still lead to the success of the regex, so regex engine didn't match anything. This zero length match thing will only happen in case of (ab)*? and not in (ab)+?, as + doesn't allow zero length matches, so regex engine will have to match 6 pairs of "ab"s (on input ababababababa)to make the regex successful. To test on my point about a*?b, you can try the regex (ab)*?b on the input abbabbabababa (note: this input is slightly different from the one in the original question)...
(PS: Henry solved my misconception about this here which made life a lot easier with regex questions for me
)
Regex Engine's first priority is the overall success of the regex. Reluctant quantifiers try to match as less as possible. They'll only match more, if that can effect the overall success of the regular expression. Suppose your regex is a*?, and your input is aaaa, then it will try to match as less as possible so it'll result only in zero length matches. But if your regex is a*?b, and input is aaabaab, then you'll get aaab and aab as matches, this time a*? matched more because otherwise the whole regex would've failed. Since in the earlier case (a*? and aaaa), zero length matches still lead to the success of the regex, so regex engine didn't match anything. This zero length match thing will only happen in case of (ab)*? and not in (ab)+?, as + doesn't allow zero length matches, so regex engine will have to match 6 pairs of "ab"s (on input ababababababa)to make the regex successful. To test on my point about a*?b, you can try the regex (ab)*?b on the input abbabbabababa (note: this input is slightly different from the one in the original question)...
(PS: Henry solved my misconception about this here which made life a lot easier with regex questions for me
)SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
| Or we might never have existed at all. Freaky. So we should cherish everything. Even this tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |








