| Author |
Please help me interpret this pattern
|
Jacob Sonia
Ranch Hand
Joined: Jun 28, 2009
Posts: 164
|
|
("<a\\b[^>]*href=\"[^>]*>(.*?)</a>")
I understand that * means 0 or more. [^] means negation, ? means 0 or 1, but i still cannot understand the whole pattern.
Thanks,
See
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
Here you can lookup what the other characters mean. Just by scanning it it appears to match a html link tag <a href="something">Something else</a>
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
Not too hot on regexes myself, but I think
Are you short of a second double-quote? You open quotes after href, but I can't see a closing quote.
That's what I can make of it. Let's see whether Rob has managed a better and quicker answer
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
Wouter Oet wrote:Here you can lookup . . .
Good idea. Another place to look is the Pattern class.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Campbell Ritchie wrote:Let's see whether Rob has managed a better and quicker answer
I would have split [^>]*href= into two separate parts, and would have explained the parentheses a bit more, but other than that it's a good explanation. And yes, a closing \" is missing.
These parentheses are probably actually used as a capturing group, allowing the user to get the hyperlink's label through the regex.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Please help me interpret this pattern
|
|
|