Results 1 to 4 of 4
Thread: Java and regular expressions
- 01-18-2013, 10:41 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 24
- Rep Power
- 0
Java and regular expressions
I want to get the favicon of a web page using jsoup.
The problem is the regular expression (probably whitespaces \\\\s).Java Code:Document doc = null; String str="http://www.java-forums.org"; try { doc = Jsoup.connect(str).get(); } catch (IOException ex) { Exceptions.printStackTrace(ex); } String urlToIcon=doc.select("link[rel~=(?i)(shortcut)?(\\\\s)+icon]").attr("abs:href"));
But I test the regex with this code and the regex works.
I test the regex here and the regex works also.Java Code:String attributeValues="icon shortcut icon ICON SHORTCUT ICON"; String regex="(?i)(shortcut)?(\\\\s)+icon"; String[ ] split = attributesValues.split(regex); for(String s:split){ System.out.println(s); }Last edited by kosmos890; 01-18-2013 at 11:49 AM.
- 01-18-2013, 02:18 PM #2
Re: Java and regular expressions
So, what's the problem?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-18-2013, 03:05 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 24
- Rep Power
- 0
Re: Java and regular expressions
From an html document, I want to extract tags like
<link rel="shortcut icon" href="/favicon.ico">
<link rel="icon" href="/favicon.ico">
<link rel="ICON" href="/favicon.ico">
but with my regex I can't.
I am beginner and I can't understand why my regex doesn't work.
If I simplify my regex to (?i)icon then I lose tags like
<link rel="shortcut icon" href="/favicon.ico">
If I change my regex to (?i).*icon then I get tags like
<link rel="apple-touch-icon" href="icon.png">
I don't want these tags.
- 01-18-2013, 03:57 PM #4
Similar Threads
-
regular expressions in java
By chkontog in forum New To JavaReplies: 2Last Post: 11-07-2012, 03:53 PM -
Java Regular Expressions: Comma Seperated List
By sgtblitz in forum New To JavaReplies: 3Last Post: 04-18-2011, 09:17 PM -
Regular Expressions Help
By Death Sickle in forum New To JavaReplies: 4Last Post: 04-04-2011, 04:21 AM -
How to create regular expressions in Java
By maz09 in forum New To JavaReplies: 12Last Post: 04-02-2010, 05:13 PM -
Regular Expressions in java
By blue404 in forum Advanced JavaReplies: 2Last Post: 09-26-2008, 03:43 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks