File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Please help me interpret this pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please help me interpret this pattern" Watch "Please help me interpret this pattern" New topic
Author

Please help me interpret this pattern

Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 172
("<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: 36453
    
  15
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: 36453
    
  15
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: 19541
    
  16

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please help me interpret this pattern
 
Similar Threads
regexp question
5 Patterns
Pattern Matching
Numeric Format
Different Message Exchange Pattern interfaces