Find & Replace {t}{/t} (RegEx) Question [Semi SOLVED]

A place to discuss things that aren't specific to any one creator or game.
Forum rules
Ren'Py specific questions should be posted in the Ren'Py Questions and Annoucements forum, not here.
Post Reply
Message
Author
bDunks
Newbie
Posts: 17
Joined: Tue Jan 08, 2019 3:07 pm
Contact:

Find & Replace {t}{/t} (RegEx) Question [Semi SOLVED]

#1 Post by bDunks » Mon Jun 03, 2019 4:49 am

Hello. :)
I know this isn't exactly a RenPy specific question, but after searching, I cannot find what I need. So hopefully some one here knows how, if possible.
I am using Sublime Text.

In my script I have a bunch of dialog that goes, e.g.

Code: Select all

pc "{mt}dialog{/mt}"
jm "{mt}dialog{/mt}"
and I want to replace all the jm dialog with

Code: Select all

jm "{ft}dialog{/ft}"
Any insight will be appreciated.
Thank you.
Last edited by bDunks on Sat Jun 22, 2019 1:59 am, edited 4 times in total.

verysunshine
Veteran
Posts: 280
Joined: Wed Sep 24, 2014 5:03 pm
Organization: Wild Rose Interactive
Contact:

Re: Find & Replace {t}{/t} Question [UNSOLVED]

#2 Post by verysunshine » Tue Jun 18, 2019 4:22 pm

Can you use Find and Replace in Sublime text?

Build the basics first, then add all the fun bits.

Please check out my games on my itch.io page!

bDunks
Newbie
Posts: 17
Joined: Tue Jan 08, 2019 3:07 pm
Contact:

Re: Find & Replace {t}{/t} Question [UNSOLVED]

#3 Post by bDunks » Thu Jun 20, 2019 3:11 am

verysunshine wrote:
Tue Jun 18, 2019 4:22 pm
Can you use Find and Replace in Sublime text?
Not without the proper input for regular expressions, which I don't know.

I have to search for:
jm "{mt}But Leave This.{/mt}"

& replace the {mt}{/mt} but leave the dialog.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 2690
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Find & Replace {t}{/t} Question [UNSOLVED]

#4 Post by Imperf3kt » Thu Jun 20, 2019 4:20 am

What I do in these situations is bust out notepad and replace all instances of jm "{mt}

Then either manually look for .{/mt}" and replace them all, or, if not shared by multiple characters, replace just that bit.

Copy/paste back into your preferred editor and done.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Todo list:
Actually finish a project

bDunks
Newbie
Posts: 17
Joined: Tue Jan 08, 2019 3:07 pm
Contact:

Re: Find & Replace {t}{/t} Question [UNSOLVED]

#5 Post by bDunks » Thu Jun 20, 2019 8:15 am

Imperf3kt wrote:
Thu Jun 20, 2019 4:20 am
What I do in these situations is bust out notepad and replace all instances of jm "{mt}

Then either manually look for .{/mt}" and replace them all, or, if not shared by multiple characters, replace just that bit.

Copy/paste back into your preferred editor and done.
Yeah, I can do that in Sublime & is what I have been doing, ha ha, but I did remember reading about reg ex & was hoping to utilize it & get it done in one swoop, as this is something that I come across often enough, that it would really save me time & be helpful.
Thanks for the input. :)

User avatar
Autumnotopia
Regular
Posts: 37
Joined: Sun May 19, 2019 8:53 pm
Tumblr: autumnotopiadev
Github: autumngreenley
itch: autumnotopia
Contact:

Re: Find & Replace {t}{/t} Question [UNSOLVED]

#6 Post by Autumnotopia » Thu Jun 20, 2019 6:45 pm

Oh, if it's like actual regex then this should be what you want:

Code: Select all

(jm "{mt})(.)+({/mt}")
(Oh and if it complains about the backslash then use this one, but I think the first one should be fine probably)

Code: Select all

(jm "{mt})(.)+({\/mt}")
Whenever I have to do regex stuff, I find RegExr really helpful (plus a regex cheatsheet site haha). That said, I've not used Sublime Text or anything so I'm not sure if that's the exact format you need.

philat
Eileen-Class Veteran
Posts: 1646
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Find & Replace {t}{/t} Question [UNSOLVED]

#7 Post by philat » Fri Jun 21, 2019 12:31 am

I mean, the ACTUAL answer is you shouldn't be doing that anyway and should be using what_prefix and what_suffix instead...

bDunks
Newbie
Posts: 17
Joined: Tue Jan 08, 2019 3:07 pm
Contact:

Re: Find & Replace {t}{/t} Question [UNSOLVED]

#8 Post by bDunks » Fri Jun 21, 2019 7:44 pm

Autumnotopia wrote:
Thu Jun 20, 2019 6:45 pm
Oh, if it's like actual regex then this should be what you want:

Code: Select all

(jm "{mt})(.)+({/mt}")
(Oh and if it complains about the backslash then use this one, but I think the first one should be fine probably)

Code: Select all

(jm "{mt})(.)+({\/mt}")
Whenever I have to do regex stuff, I find RegExr really helpful (plus a regex cheatsheet site haha). That said, I've not used Sublime Text or anything so I'm not sure if that's the exact format you need.
I tried it both in Sublime & Notepad++, unfortunately it does not work. I have tried that one before, or something very similar.
Does that site work for Python, because I don't see it as an option in the pulldown? Or does it not matter?
Appreciate your time & the links! :)
Last edited by bDunks on Fri Jun 21, 2019 8:06 pm, edited 1 time in total.

bDunks
Newbie
Posts: 17
Joined: Tue Jan 08, 2019 3:07 pm
Contact:

Re: Find & Replace {t}{/t} Question [UNSOLVED]

#9 Post by bDunks » Fri Jun 21, 2019 7:45 pm

philat wrote:
Fri Jun 21, 2019 12:31 am
I mean, the ACTUAL answer is you shouldn't be doing that anyway and should be using what_prefix and what_suffix instead...
Can you please elaborate?

I used to use Autohotkey to stylize text.
e.g.

Code: Select all

{i}{color=#76e6f7}TEXT{/color}{/i}
Later I found a piece of code like this

Code: Select all

init python:
    def male_thought(tag, argument, contents):
        return [
            (renpy.TEXT_TAG, u"i"),
            (renpy.TEXT_TAG, u"color=#ff9000"),
        ] + contents + [
            (renpy.TEXT_TAG, u"/color"),
            (renpy.TEXT_TAG, u"/i"),
        ]
    config.custom_text_tags["mt"] = male_thought

I thought this looked much cleaner.
How does what you are recommending work?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 2690
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Find & Replace {t}{/t} (RegEx) Question [UNSOLVED]

#10 Post by Imperf3kt » Fri Jun 21, 2019 9:18 pm

If you want to use the tags to later place a style inline, you're better off just using a style prefix.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Todo list:
Actually finish a project

User avatar
Autumnotopia
Regular
Posts: 37
Joined: Sun May 19, 2019 8:53 pm
Tumblr: autumnotopiadev
Github: autumngreenley
itch: autumnotopia
Contact:

Re: Find & Replace {t}{/t} Question [UNSOLVED]

#11 Post by Autumnotopia » Fri Jun 21, 2019 10:10 pm

bDunks wrote:
Fri Jun 21, 2019 7:44 pm
I tried it both in Sublime & Notepad++, unfortunately it does not work. I have tried that one before, or something very similar.
Does that site work for Python, because I don't see it as an option in the pulldown? Or does it not matter?
Appreciate your time & the links! :)
Got it, it looks like this site covers Python regex. The main thing being that it wanted me to use an escape character for the quotation marks too haha. A lot of time when there's a character that's commonly used in code as well (things like / or ") it needs a character to tell it to literally use that char instead of it being some code thing (this is known as an escape character, often a \). Does this work?

Code: Select all

(jm \"{mt})(.)+({\/mt}\")
(Regex is useful to get a grasp on just in general for situations like this, though yeah if every line of dialogue from a character uses the same style tag it would probably be better to use a prefix)

bDunks
Newbie
Posts: 17
Joined: Tue Jan 08, 2019 3:07 pm
Contact:

Re: Find & Replace {t}{/t} Question [UNSOLVED]

#12 Post by bDunks » Sat Jun 22, 2019 1:26 am

Autumnotopia wrote:
Fri Jun 21, 2019 10:10 pm
bDunks wrote:
Fri Jun 21, 2019 7:44 pm
I tried it both in Sublime & Notepad++, unfortunately it does not work. I have tried that one before, or something very similar.
Does that site work for Python, because I don't see it as an option in the pulldown? Or does it not matter?
Appreciate your time & the links! :)
Got it, it looks like this site covers Python regex. The main thing being that it wanted me to use an escape character for the quotation marks too haha. A lot of time when there's a character that's commonly used in code as well (things like / or ") it needs a character to tell it to literally use that char instead of it being some code thing (this is known as an escape character, often a \). Does this work?

Code: Select all

(jm \"{mt})(.)+({\/mt}\")
(Regex is useful to get a grasp on just in general for situations like this, though yeah if every line of dialogue from a character uses the same style tag it would probably be better to use a prefix)
Ahha!
This isn't exactly correct, but after seeing what you did I modified it slightly. You have to also include these

Code: Select all

{}
so this works for finding! :D

Code: Select all

(jm \"\{mt\})(.)+(\{\/mt\}\")
But I am not sure what to use when replacing to keep the text in between the tags. With this new insight, I hope to figure it out.
Thanks for all of your help! :)

And thank you to all that replied with their input. :)

If & when I find a solution, I will post here for any others looking for this info.


Ughh... I feel like I'm really close with replace with:

Code: Select all

jm "{ft}$&{/ft}"

philat
Eileen-Class Veteran
Posts: 1646
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Find & Replace {t}{/t} (RegEx) Question [Semi SOLVED]

#13 Post by philat » Mon Jun 24, 2019 8:49 pm

https://www.renpy.org/doc/html/dialogue.html#Character

The descriptions of what_prefix and what_suffix seems self-explanatory, tbh.

bDunks
Newbie
Posts: 17
Joined: Tue Jan 08, 2019 3:07 pm
Contact:

Re: Find & Replace {t}{/t} (RegEx) Question [Semi SOLVED]

#14 Post by bDunks » Tue Jun 25, 2019 7:01 pm

philat wrote:
Mon Jun 24, 2019 8:49 pm
https://www.renpy.org/doc/html/dialogue.html#Character

The descriptions of what_prefix and what_suffix seems self-explanatory, tbh.
Thanks for the link. After taking a look, it currently is not what I am looking for, nor does it resolve my current situation, since I am only doing this for inner thought/dialog & narration. I could see the usefulness if I was stylizing all the text for a specific character, though.
I could create a character for thought, for example, but when it comes down to it, with using macros, it seems more like a preference. I press a button & it shoots out the char name, quotes, tags & puts my cursor in the middle, ready to add text.
None the less, it is something new for the old vault, ha ha, so I thank you for the info. :)

philat
Eileen-Class Veteran
Posts: 1646
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Find & Replace {t}{/t} (RegEx) Question [Semi SOLVED]

#15 Post by philat » Thu Jun 27, 2019 9:20 pm

Sure, it's a preference, until you want to change the tag again. ;) Anyway, good luck with the rest of your game.

Post Reply

Who is online

Users browsing this forum: solarProtag