Results 1 to 4 of 4
- 11-21-2011, 10:53 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 22
- Rep Power
- 0
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?
- 11-22-2011, 06:07 AM #2
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 11-22-2011, 06:11 AM #3
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 11-23-2011, 02:05 AM #4
Member
- Join Date
- Oct 2011
- Posts
- 22
- Rep Power
- 0
Similar Threads
-
Need help with regex pattern
By b_jones10634 in forum Advanced JavaReplies: 1Last Post: 09-24-2010, 08:02 PM -
Regex for the pattern
By mallikarjun_sg in forum Advanced JavaReplies: 12Last Post: 05-06-2010, 12:16 PM -
Specific syntax? java.util.regex.Pattern$Node
By lmhelp2 in forum New To JavaReplies: 1Last Post: 04-09-2010, 11:32 AM -
Regex Pattern/Matcher - Print only one occurrence!
By racha0601 in forum Advanced JavaReplies: 3Last Post: 04-06-2009, 05:05 PM -
Regex pattern
By ravian in forum New To JavaReplies: 4Last Post: 12-11-2007, 10:20 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks