Solved

Reg expression gurus

Posted on 2004-04-05
4
366 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
  • 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 125 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven project error 5 56
Java exception bubble up 2 18
runtime exception 2 28
login form jsp example 2 26
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

803 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