Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile pattern quote inside quote

Tags:

java

regex

So I need to compile a pattern that includes a set of " " inside it . It won't do the job any other pattern Using this pattern compare.

Pattern urlPattern = Pattern.compile("<div class="thumb"><a href=(.*?)-t1");

I am reading about it and you need to do something like "\stuff\" but I just can't work it in the pattern above. Any help?

like image 825
anno Avatar asked Sep 14 '26 01:09

anno


1 Answers

Escape your quotes:

Pattern myPattern = Pattern.compile("<div class=\"thumb\"><a href=(.*?)-t1");

Also, regex against HTML is usually considered to be bad practice.

like image 145
Mena Avatar answered Sep 15 '26 14:09

Mena



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!