0

In my app, i get a list of strings as a response to the http request. In those strings, some strings may contain a html tag at the beginning. The format of the string is like this <span class="qtO">String. I want to replace the <span> part. But, the qtO part of the string can be anything. It can be qt1, qt2.., qtA, qtB..,qta, qtb.. etc. Thats why i decided to use the Regex. I new to this and I set the pattern string like this:

 String regex = '<span class=\"[a-z]{1}[a-z]{1}[A-Z]{1}\"';`

I dont know if it is right. I use the following code to test:

Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(rTitle);
if (m.find()) {
    System.debug('TITLE: ' + rTitle);
}

But, the code is not entering into the if block. I am pretty sure that the pattern string is wrong. So, what modifications i have to do to make the pattern string right?

0

1 Answer 1

0

I solved it. I replaced the pattern string from '<span class=\"[a-z]{1}[a-z]{1}[A-Z]{1}\"' to '<span class=\"qt[a-zA-Z0-9]{1}\">' and now it works fine. It took a little bit of time for me to understand how Regex works.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .