The first step is to write a regular expression. I have made a tutorial about them here:
http://www.rmxp.org/forums/showthread.php?t=21009
You can use the one I give here: (
\k[string] and
\K[string] accepted where string consists of any
The parenthesis around the (.*?) are there for back reference purposes.
.*? and not .* because we would not want a greedy approach.
To keep in the spirit of a message system I'll as an example modify the default message system. (Having any custom scripts may mess this up)
I suggest you make a new project, a test project if you want to test this.,
Go to around line 90 with the
text.gsub!(/\\[Gg]/) { "\002" }
Below this we make insert this line:
text.gsub!(/\\[Kk]\[(.*?)\]/) {"\003" + $1 + "\003"}
This replaces the
\k[String] with with
\003String\003
The $1 is a back reference to the first parenthesis. You only have one () so it 's easy in this case.
The reason I put two
\003 was to have one to open and one to close.
If the start and ending should act differently then just use this block instead:
{"\003" + $1 + "\003"}
This alone is not enough. Now you have just change the string.
Luckily a great help have been given for the next step. Let's look in this while loop:
while ((c = text.slice!(/./m)) != nil)
Note:
# If \G
if c == "\002"
# stuff...
end
We just have to define actions in an if-branch for our
\003.
We'll use this:
# If bold and italic
if c == "\003"
font = self.contents.font
font.bold = !font.bold
font.italic = !font.italic
end
This simple says that if it meets a
\003 it will change the font to be the opposite of what it was before in case being
bold and
italic.
That is... if the font is not bold, it will make the font bold, otherwise it will make the font non-bold
If the font is not italic, it will make the font italic, otherwise it will make the font non-italic.
I hope I have helped you enough ^_^
-
Zeriab