HalHaxor
HalHaxor

Reputation: 31

Having trouble getting part of an HTML line in Java with regex

I'm trying to get a part of a line in an HTML line with a regular expression but I can't get it to work.

Here is the html (necessary) part :

(five random numbers)/ ">(the word I want to extract, between 2 and 45 characters)<

So I'm using this regex:

"[0-9]{5}\\/\\\"\\s\\>(\\.{1,45})\\<"

And I can't get it to work...

I always get a "no match found" when I try to get my word via group() after a .find() of my Matcher. Hope I'm clear enough!

Upvotes: 1

Views: 67

Answers (1)

Joop Eggen
Joop Eggen

Reputation: 109557

This should do:

"[0-9]{5}/\"\\s>(.{1,45})<"

Maybe better

"\\d{5}/\"\\s*>([^<]{1,45})<"

which will also allows newline to be captured, and prevents ending with a later second <.

Upvotes: 2

Related Questions