Find values between markers?

S_Rank_Crazy

Veteran
Veteran
Joined
Dec 30, 2015
Messages
78
Reaction score
47
First Language
English
Primarily Uses
RMMV
Hey guys,

In all my years of programming, regular expressions have just been the bane of my existence, but sadly my knowledge of how they function just isn't enough to solve my current problem. Basically I'm looking to set up some escape-string functionality, like that found in the message window. For example, I have:

\IDENTIFIER[KEY: VALUE]

Where IDENTIFIER is a string with more than one character, I had it working using:

/\\IDENTIFIER\[(\w+):[ ](\w+)\]/Though my test case only had my code in the message window. Once I added some other text, it just broke. It also broke when I made VALUE be more than one word, which is expected I guess because of the second capture group (\w+). I tried using (.+) to cater for that but that just matches the entire message block.

Any of you wizards have any idea how to get this to work? I know the Yanfly plugins use similar regex statements but seemingly nothing I can one-to-one against to see where I'm going wrong.
 
Last edited by a moderator:

Sarkilas

Villager
Member
Joined
Jun 8, 2014
Messages
16
Reaction score
7
First Language
Norwegian
If KEY is always one word, but VALUE can be multiple words, your regex is correct apart from the second capture group as you expected. The fixed regex would be like this:

/\\IDENTIFIER\[(\w+):[ ](.*?)\]/I also suggest using a case insensitive modifier on your regex so you can type \identifier as well as \IDENTIFIER to be less strict.

The (.*?) capture group is a lazy capture (as opposed to greedy), where it matches all characters except newline.

As for it breaking when you add more text to the message, that's likely a code flaw, as there's nothing wrong with capturing in this regex.

Hope this explains it well enough for you.
 
Last edited by a moderator:

S_Rank_Crazy

Veteran
Veteran
Joined
Dec 30, 2015
Messages
78
Reaction score
47
First Language
English
Primarily Uses
RMMV
Thanks so much, been pulling my hair out over this. Looks like once I changed it to lazy it doesn't break with the other text, though might've inadvertently fixed something else in the code. Also, I am using 'g' and 'i' flags for the regex :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,977
Members
137,563
Latest member
cexojow
Top