Replace text between 2 characters



  • Hello,

    I want to replace all the text in my text file with a certain thing

    For example, if we take the text:

    John sat on the mat and said"the fat cat ate the rat"and matt said"what about a bat"presumptuously.

    I want to make it so the text between the each group of speech marks is replaced with the exact same thing except with spaces at the start and end.

    John sat on the mat and said “the fat cat ate the rat” and matt said “what about a bat” presumptuously.

    Of course, the text file is much larger and I would hate to go through it all doing this manually.



  • Hello, @comic_sans-criminal2 and All,

    No problem ! But I noticed that your “Before” text contained regular Quotation Marks ( \x{0022} ), whereas your “After” text contained Left Double Quotation Marks ( \x{201C} ) and Right double quotation marks ( \x{201D} )

    Refer to http://www.unicode.org/charts/PDF/U2000.pdf

    Anyway, the regex S/R , below, will match three 3 characters !


    So :

    • Open the Replace panel ( Ctrl + H )

    • Select the Regular expression search mode

    • Tick the Wrap around option

    • Type (?-s)["“](.+?)["”] , in the Find what: zone

    • And, in the Replace with zone :

      • Write \x20"\1"\x20 , if you need regular quotation marks

      • Use, instead, \x20“\1”\x20 , if you prefer stylistic quotation marks

    • Click on the Replace All button

    Voilà !

    Best Regards,

    guy038



  • @guy038 said:

    \x20"\1"\x20

    Nice! This was exactly what I was looking for, thank you very much


Log in to reply