Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reg expression gurus

Posted on 2004-04-05
4
Medium Priority
?
373 Views
Last Modified: 2010-03-31
I want to get every href in page into array.
So <A href= "Link1">Link1</A><BR><A href= "Link2">Link2<H3><A name="Link3">Link3</A></H3>
I want 3 ref to Link1, Link2, and Link3
Any reg exp that can do this?
0
Comment
Question by:Paullkha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Thandava Vallepalli
ID: 10757928
Hello,

http://www.regular-expressions.info/examples.html

Eg:

"<a[^>]*>(.*?)</a>"

All the best,
V.Thandava Krishna.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10759883
You need to make that regex part of a case-insensitive match or it won't work

final String RE_LINK = "<a[^>]*>(.*?)</a>";
Pattern pattern = Pattern.compile(RE_LINK, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(yourString);
0
 
LVL 30

Accepted Solution

by:
GrandSchtroumpf earned 500 total points
ID: 10760713
You can do it in 2 steps: split and replaceFirst

    String splitRegExp   = "<[A-a] [^>]*>";
    String matchRegExp   = "</[A-a]>.*";
    String replaceRegExp = "";

    String[] splitStrings = (test).split(splitRegExp);
    String[] anchorStrings = new String[splitStrings.length - 1];
    for (int i = 1; i < splitStrings.length; i++) {
      anchorStrings[i - 1] = splitStrings[i].replaceFirst(matchRegExp, replaceRegExp);
    }
    System.out.println(Arrays.asList(anchorStrings).toString());
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10944480
:°)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question