Solved

Reg expression gurus

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iterator/ListIterator approach 17 55
mysql jsp example issue 32 75
web project error add remove 1 56
program arguments vs VM arguments 4 32
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

696 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