Page 1 of 2
Find & Replace {t}{/t} (RegEx) Question [SOLVED]
Posted: Mon Jun 03, 2019 4:49 am
by bDunks
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
Any insight will be appreciated.
Thank you.
Answer
Find:
Replace:
Re: Find & Replace {t}{/t} Question [UNSOLVED]
Posted: Tue Jun 18, 2019 4:22 pm
by verysunshine
Can you use Find and Replace in Sublime text?
Re: Find & Replace {t}{/t} Question [UNSOLVED]
Posted: Thu Jun 20, 2019 3:11 am
by bDunks
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.
Re: Find & Replace {t}{/t} Question [UNSOLVED]
Posted: Thu Jun 20, 2019 4:20 am
by Imperf3kt
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.
Re: Find & Replace {t}{/t} Question [UNSOLVED]
Posted: Thu Jun 20, 2019 8:15 am
by bDunks
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.

Re: Find & Replace {t}{/t} Question [UNSOLVED]
Posted: Thu Jun 20, 2019 6:45 pm
by Autumnotopia
Oh, if it's like actual regex then this should be what you want:
(Oh and if it complains about the backslash then use this one, but I think the first one should be fine probably)
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.
Re: Find & Replace {t}{/t} Question [UNSOLVED]
Posted: Fri Jun 21, 2019 12:31 am
by philat
I mean, the ACTUAL answer is you shouldn't be doing that anyway and should be using what_prefix and what_suffix instead...
Re: Find & Replace {t}{/t} Question [UNSOLVED]
Posted: Fri Jun 21, 2019 7:44 pm
by bDunks
Autumnotopia wrote: ↑Thu Jun 20, 2019 6:45 pm
Oh, if it's like actual regex then this should be what you want:
(Oh and if it complains about the backslash then use this one, but I think the first one should be fine probably)
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!

Re: Find & Replace {t}{/t} Question [UNSOLVED]
Posted: Fri Jun 21, 2019 7:45 pm
by bDunks
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?
Re: Find & Replace {t}{/t} (RegEx) Question [UNSOLVED]
Posted: Fri Jun 21, 2019 9:18 pm
by Imperf3kt
If you want to use the tags to later place a style inline, you're better off just using a style prefix.
Re: Find & Replace {t}{/t} Question [UNSOLVED]
Posted: Fri Jun 21, 2019 10:10 pm
by Autumnotopia
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?
(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)
Re: Find & Replace {t}{/t} Question [UNSOLVED]
Posted: Sat Jun 22, 2019 1:26 am
by bDunks
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?
(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
so this works for finding!
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:
Re: Find & Replace {t}{/t} (RegEx) Question [Semi SOLVED]
Posted: Mon Jun 24, 2019 8:49 pm
by philat
https://www.renpy.org/doc/html/dialogue.html#Character
The descriptions of what_prefix and what_suffix seems self-explanatory, tbh.
Re: Find & Replace {t}{/t} (RegEx) Question [Semi SOLVED]
Posted: Tue Jun 25, 2019 7:01 pm
by bDunks
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.

Re: Find & Replace {t}{/t} (RegEx) Question [Semi SOLVED]
Posted: Thu Jun 27, 2019 9:20 pm
by philat
Sure, it's a preference, until you want to change the tag again.

Anyway, good luck with the rest of your game.