Results 1 to 4 of 4
  1. #1
    fishy8158 is offline Member
    Join Date
    Oct 2011
    Posts
    22
    Rep Power
    0

    Default regex.pattern need help understanding

    I am trying to learn how to use the match functions, and i have trouble understanding the following code.

    htmltag=pattern.compile(<a\\b[^>]*href=\"[^>]*>(.*?)</a>)

    I have read the java artical about patterns but i still don't understand the code line,

    From what i understand, its trying to compile( "<a\" X," href=\" X (oneormoretimes) X (any letters , one or more times) </a>)
    Can anyone explain the X?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: regex.pattern need help understanding

    The backslash is an escape character for String literals, and also an escape character for regexes. So the "\\b" in the String literal is parsed to "\b" in the String variable and interpreted as such be the regex compilation: as a word boundary character.

    Here are a couple of good learning resources:
    Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns
    Lesson: Regular Expressions (The Java™ Tutorials > Essential Classes)

    And you missed the quotes around the String literal, and using code tags to post code.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: regex.pattern need help understanding

    What you refer to as "X" is a character class. You can read up on it in either (or both) of the resources linked.

    Also note that ^ within a character class is negation.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    fishy8158 is offline Member
    Join Date
    Oct 2011
    Posts
    22
    Rep Power
    0

    Default Re: regex.pattern need help understanding

    Thanks for the links, ill look into it.

Similar Threads

  1. Need help with regex pattern
    By b_jones10634 in forum Advanced Java
    Replies: 1
    Last Post: 09-24-2010, 08:02 PM
  2. Regex for the pattern
    By mallikarjun_sg in forum Advanced Java
    Replies: 12
    Last Post: 05-06-2010, 12:16 PM
  3. Specific syntax? java.util.regex.Pattern$Node
    By lmhelp2 in forum New To Java
    Replies: 1
    Last Post: 04-09-2010, 11:32 AM
  4. Regex Pattern/Matcher - Print only one occurrence!
    By racha0601 in forum Advanced Java
    Replies: 3
    Last Post: 04-06-2009, 05:05 PM
  5. Regex pattern
    By ravian in forum New To Java
    Replies: 4
    Last Post: 12-11-2007, 10:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •