/    Sign up×
Community /Pin to ProfileBookmark

hmm what’s wrong here…

I’ve modified this code several times. Now it starts matching at the FIRST instance and considers matcher.group(1) to be the entire rest of file from that match on…

IE instead of matching just :
[url]http://www.yahoo.com[/url]

It matches
http://www.yahoo.com”>Click here to go to yahoo.</a><br> —- AND ON

[code]
public void ProcessURL(String Info) {
if (Info == null) {
System.exit(1);
}
System.out.println(“Processing page for URLs…”);
Pattern url_pat = Pattern.compile(“.*href=”(.+)”.*”);
Matcher matcher = url_pat.matcher( Info );
if( matcher.find()) {
//System.out.println(“Total Matches: ” + matcher.matches());
String ftest = null;
for (int i = 1;i <= matcher.groupCount();i++) {
System.out.println(“Matched: (” + matcher.group(0) + “)”);
}
} else {
System.out.println(“No matches found.”);
}
System.out.println(“Done processing page for URLs.”);
}
[/code]

to post a comment
Java

1 Comments(s)

Copy linkTweet thisAlerts:
@afmookauthorMay 11.2006 — Figured it out. Code for anyone who wants:

public void ProcessURL(String Info) {
if (Info == null) {
System.exit(1);
}
System.out.println("Processing page for URLs...");
Pattern url_pat = Pattern.compile("href="(.+?")");
Matcher matcher = url_pat.matcher( Info );
if (!matcher.find()) { System.out.println("No matches found."); }
while( matcher.find()) {
String ftest = matcher.group(1);
System.out.println("Matched: (" + ftest + ")");
}
System.out.println("Done processing page for URLs.");
}
×

Success!

Help @afmook spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...