Solved

Reg expression gurus

Posted on 2004-04-05
4
365 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mapAB Challlenge 35 124
jar file executable 12 39
egit plugin on eclipse 8 31
table example 4 21
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

911 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now