Note that there are some explanatory texts on larger screens.

plurals
  1. POString.replaceFirst does not replace the expected string sometimes
    primarykey
    data
    text
    <p>Using java i try to replace occurence of certain string with other one. It works in most of the cases. But sometimes that certain string is not replaced in the given content. </p> <p>When i search that certain string in the given content using indexOf method, i can correctly get the index of that String. But when i use replaceFirst method to replace that String, the operation ends with unsuccess.</p> <p>Then i tried to replace using following in order to escape from escape characters.</p> <pre><code>cont = Pattern.compile(str, Pattern.LITERAL).matcher(cont) .replaceFirst(Matcher.quoteReplacement("replace string")) </code></pre> <p>Lets us take below content as example</p> <blockquote> <p>For the pictures of animal please visit this site <a href="http://www.example.net/animals/cat_345_456.JPG" rel="nofollow">http://www.example.net/animals/cat_345_456.JPG</a> . Also more details visit this link also <a href="http://www.moredetails.com/example/imgs/nwr_1453446_83223_429054_1603367_42.PNG?Id=1450686&amp;lid=423454&amp;idp=4402767&amp;ps=4563223&amp;circle=4&amp;type=2&amp;zw=264&amp;zh=150&amp;v=5&amp;url=NA&amp;uid=" rel="nofollow">http://www.moredetails.com/example/imgs/nwr_1453446_83223_429054_1603367_42.PNG?Id=1450686&amp;lid=423454&amp;idp=4402767&amp;ps=4563223&amp;circle=4&amp;type=2&amp;zw=264&amp;zh=150&amp;v=5&amp;url=NA&amp;uid=</a> . Thanks visiting us.</p> </blockquote> <p>In the above content First i assign str with value of <a href="http://www.example.net/animals/cat_345_456.JPG" rel="nofollow">http://www.example.net/animals/cat_345_456.JPG</a> and then i call replace first method.</p> <p>In this case expected string replaces correctly.</p> <p>Then now i assign str with value of <a href="http://www.moredetails.com/example/imgs/nwr_1453446_83223_429054_1603367_42.PNG?Id=1450686&amp;lid=423454&amp;idp=4402767&amp;ps=4563223&amp;circle=4&amp;type=2&amp;zw=264&amp;zh=150&amp;v=5&amp;url=NA&amp;uid=" rel="nofollow">http://www.moredetails.com/example/imgs/nwr_1453446_83223_429054_1603367_42.PNG?Id=1450686&amp;lid=423454&amp;idp=4402767&amp;ps=4563223&amp;circle=4&amp;type=2&amp;zw=264&amp;zh=150&amp;v=5&amp;url=NA&amp;uid=</a> and i call replace first method.</p> <p>But this time it doesn't got replaced. But when i use String.indexof method it correctly gives index number of that String. </p> <p>Am i missing anything?</p> <p>Please help. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload