Title: Replace specific word inside &#8220;li&#8221;
Last modified: December 29, 2020

---

# Replace specific word inside “li”

 *  Resolved [Taufan](https://wordpress.org/support/users/taufanxxx/)
 * (@taufanxxx)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/replace-specific-word-inside/)
 * Hi,
    Im new on this Regex. Please help me. I wanna Replace this:
 * `<li class="keywords"><img draggable="false" role="img"> #Apple #SoutheastAsia
   </li>`
 * To this:
 * `<li class="keywords"><img draggable="false" role="img"> <a href="">#Apple</a
   > #SoutheastAsia</li>`
 * I dont wanna replace other “#Apple” outside the “li” tag.
 * I already search on Stackoverflow but the code never works as i expexted.
 * Thanks for your help.
    I really appreciated.
    -  This topic was modified 5 years, 5 months ago by [Taufan](https://wordpress.org/support/users/taufanxxx/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Marios Alexandrou](https://wordpress.org/support/users/marios-alexandrou/)
 * (@marios-alexandrou)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/replace-specific-word-inside/#post-13845936)
 * What find and replace rule have you tried?
 *  Thread Starter [Taufan](https://wordpress.org/support/users/taufanxxx/)
 * (@taufanxxx)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/replace-specific-word-inside/#post-13845966)
 * I try
    Replace: `/(<.*?>)(.*Apple?)(<*.*?>)/`
 * With:
 * `$1<a href="">#Apple</a>$3`
 * But I dont know what is that.
    The result is Blank page.
    -  This reply was modified 5 years, 5 months ago by [Taufan](https://wordpress.org/support/users/taufanxxx/).
    -  This reply was modified 5 years, 5 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
 *  Plugin Author [Marios Alexandrou](https://wordpress.org/support/users/marios-alexandrou/)
 * (@marios-alexandrou)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/replace-specific-word-inside/#post-13846428)
 * I think you’re probably over complicating things. I would:
 * 1. Start with a regex rule that just replaces the Apple portion with what you
   want.
    2. After you have the Apple portion working, add an extra bit at the beginning
   to match the li tag or the img tag. 3. I don’t see a reason why you need to match
   anything after the Apple so you can get rid of 1/3 the rule.
 * Finally, if the li tag is the same in all cases, you may not even need regex.
   Just do a simple match of the li tag including the Apple and replace it with 
   the li tag with the modified Apple.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Replace specific word inside “li”’ is closed to new replies.

 * ![](https://ps.w.org/real-time-find-and-replace/assets/icon-256x256.png?rev=1347950)
 * [Real-Time Find and Replace](https://wordpress.org/plugins/real-time-find-and-replace/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/real-time-find-and-replace/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/real-time-find-and-replace/)
 * [Active Topics](https://wordpress.org/support/plugin/real-time-find-and-replace/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/real-time-find-and-replace/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/real-time-find-and-replace/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Marios Alexandrou](https://wordpress.org/support/users/marios-alexandrou/)
 * Last activity: [5 years, 5 months ago](https://wordpress.org/support/topic/replace-specific-word-inside/#post-13846428)
 * Status: resolved