| Author |
what is the meaning of below regular expression
|
subba rao
Greenhorn
Joined: Apr 24, 2008
Posts: 24
|
|
what is the meaning of below regular expression
.*?(?:\\d-)+\\w+)/.*
|
 |
John Jai
Bartender
Joined: May 31, 2011
Posts: 1776
|
|
|
Any particular part you were not able to relate to http://docs.oracle.com/javase/tutorial/essential/regex/pre_char_classes.html and http://docs.oracle.com/javase/tutorial/essential/regex/quant.html?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
With the help of java.util.regex.Pattern:
. means any character
.* means any character zero or more times
.*? means the "any" should be taken reluctantly
(?: is the start of a non-capturing group
\\d means a single digit
(?:\\d-) means a single digit followed by a -, as a non-capturing group
(?:\\d-)+ indicates that part should be taken one or more times
\\w means a single word character
\\w+ means one or more word characters
) is the closing of a group (capturing or not); it's start is missing here
/.* is a single / followed by anything
I think you missed one ( and the regex should have been .*?((?:\\d-)+\\w+)/.*. This would make the digits plus word characters a capturing group which can later be extracted. The regex would match things like dasdas1-a/dasdas, asdas1-3-bsdsa/dasdasdsa, etc; 1-a and 1-3-bsdsa would be captured by the group.
Note that the first part is reluctant, because otherwise the second string would have lead to 3-bsdsa; the 1- would be part of the .*.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
subba rao
Greenhorn
Joined: Apr 24, 2008
Posts: 24
|
|
|
thanks for the explaination ROB
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
You're welcome.
|
 |
 |
|
|
subject: what is the meaning of below regular expression
|
|
|