Community
    • Login

    Replace html tag with regular expression

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    htmlxmlnewbie
    2 Posts 2 Posters 3.2k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Linh ViệtL Offline
      Linh Việt
      last edited by

      Hello everyone. I have this html code:

      <hint><type="book"><string-name><surname>Alex</surname>, <given-names>Nere</given-names></string-name>, <year>2012</year>, <article-title>The Dark Side of Money</article-title>, <source>Priest With A Goal</source></type></hint>
      <hint><type="journal"><string-name><surname>Radosław</surname>, <given-names>Natali</given-names></string-name>, <year>2013</year>, <article-title>8 Mood-Boosting Benefits of Money</article-title>, <source>Phantom Without A Conscience</source>, <volume>1</volume></type></hint>
      <hint><type="journal"><string-name><surname>Eamon</surname>, <given-names>Heino</given-names></string-name>, <year>2014</year>, <article-title>How Millennials Are Disrupting Money</article-title>, <source>Humans Of Power</source>, <volume>II</volume></type></hint>
      <hint><type="other"><string-name><surname>Marta</surname>, <given-names>Amice</given-names></string-name>, <year>2015</year>, <article-title>Here's My Secret Sauce for Success in Money</article-title>, <source>Enemies Of The Nation</source>, <issue>2</issue></type></hint>
      <hint><type="other"><string-name><surname>Vepkhia</surname>, <given-names>Terrie</given-names></string-name>, <year>2016</year>, <article-title>Why the Money Business Is Flirting With Disaster</article-title>, <source>Lords And Priests</source></type></hint>
      <hint><type="book"><string-name><surname>Ulf</surname>, <given-names>Nima</given-names></string-name>, <year>2017</year>, <article-title>13 Hilarious Tweets About Money</article-title>, <source>Aliens And Turtles</source></type></hint>
      <hint><type="other"><string-name><surname>Baard</surname>, <given-names>Irine</given-names></string-name>, <year>2018</year>, <article-title>Forget Everything You’ve Ever Known About Money</article-title>, <source>Faction Without Courage</source></type></hint>
      <hint><type="other"><string-name><surname>Kalyani</surname>, <given-names>Loreta</given-names></string-name>, <year>2019</year>, <article-title>This Will Fundamentally Change the Way You Look at Money</article-title>, <source>Construction Of Joy</source></type></hint>
      <hint><type="journal"><string-name><surname>Hubertus</surname>, <given-names>Camilla</given-names></string-name>, <year>2020</year>, <article-title>The 15 Best War Sites on the Internet</article-title>, <source>Never Trust The North</source>, <volume>I</volume>, <issue>1</issue></type></hint>
      

      I want replace all <article-title> to <chapter-title> where <type=“book”>
      Can anyone give me a solution to this problem because the line in my file is a lot
      Thanks for reading and giving me the solution

      Best regards!

      PeterJonesP 1 Reply Last reply Reply Quote 1
      • PeterJonesP Online
        PeterJones @Linh Việt
        last edited by PeterJones

        @Linh-Việt ,

        So, you want to replace any <article-title> with <chapter-title>, but only when inside a <type="book"> .... </type> pair, and not between other types, like <type="journal">...</type>?

        That sounds like a job for FAQs > Generic Regex > Replacing in a specific zone of text , where you could use:

        • Find Regex FR = article-title>
        • Replacement Regex RR = chapter-title>
        • Begin Search Region BSR = <type="book">
        • End Search Region ESR = </type>

        Using those values in the bold “variables” in the regex shown in that article, you would get:

        • Find What = (?-si:<type="book">|(?!\A)\G)(?s-i:(?!</type>).)*?\K(?-si:article-title>)
        • Replace With = chapter-title>
        • Replace All will convert the text for you.
          • (doing multiple Replace commands won’t necessarily work, because of the way that \K works)

        BTW: thanks for formatting your example data correctly. It helps us make sure we read your data correctly!

        -—

        Useful References

        • Notepad++ Online User Manual: Searching/Regex
        • FAQ: Where to find other regular expressions (regex) documentation
        1 Reply Last reply Reply Quote 1

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors