zahir
zahir

Reputation: 31

use regex for get values java

i want to how to get separate text from group of contents in java..

example

String a = "area href=\"hai.com\"  jkjfkjs </area> ndkjfkjsdfj dfjkdsjfl jkdf dljflsd fljdf kd;fsd a href=\"hoo.com\"  sdf</a> jisdjfi jdojfis joij";

i would like to get href link only..

how to write regex..

thanks and advance

Upvotes: 2

Views: 627

Answers (2)

lugte098
lugte098

Reputation: 2309

Try:

import java.util.regex.Pattern;
String textToSearch = "[Some text to search through]";
Pattern regex = Pattern.compile("href=\"(.*?)\"")

Upvotes: 1

Mnementh
Mnementh

Reputation: 51311

That should do the trick.

String text = ...
Matcher matcher Pattern.compile("href=\"(.*?)\"").matcher(text);
while (matcher.find())
{
   String hrefcontent = matcher.group(1);
}

Upvotes: 4

Related Questions