My regexp -_-

Hi guys !

Can you help on my regular expression please ?

i need this configuration in the Note Skills :

<synthesis>
type: (B or N)
tabIdx: x
tabIDy: y
skillId: number
actoreId: number
<\synthesis>

or this :

<synthesis:[B,x,y,skillId,actorId]>

thanks for your help ^^
I assume you are using a plugin? Got a link to it? Where is the regular expression? Nothing you've got there has anything to do with regular expressions.
Hi Shaz ^^,

i not use plugin, i create a plugin 🙂.

my regular expression is :

var regexp = /\<synthesis\:\[(.*)\]/

Can you help me ? ^^
tbh, I don't know how people set up their plugins to allow for multi-line notes, and regexp and I don't get along well at all. Grab one of Yanfly's and see how he does it. Sorry I couldn't be more helpful.
Ok thanks Shaz ^^

i'm waiting for help 🙂

i see this on Yanfly Item Durability plugin :

var evalMode = 'none';
obj.breakEval = '';

for (var i = 0; i < notedata.length; i++) {
var line = notedata;
if (line.match(/<DURABILITY:[ ](\d+)>/i)) {
obj.durability = Math.max(1, parseInt(RegExp.$1));
} else if (line.match(/<DURABILITY VARIANCE:[ ](\d+)>/i)) {
obj.durVariance = parseInt(RegExp.$1);
} else if (line.match(/<DURABILITY MAXIMUM:[ ](\d+)>/i)) {
obj.durMax = parseInt(RegExp.$1);
} else if (line.match(/<(?:UNBREAKABLE|BYPASS DURABILITY)>/i)) {
obj.durability = -1;
} else if (line.match(/<BREAK SOUND NAME:[ ](.*)>/i)) {
obj.breakSound['name'] = String(RegExp.$1);
} else if (line.match(/<BREAK SOUND VOLUME:[ ](\d+)>/i)) {
obj.breakSound['volume'] = parseInt(RegExp.$1);
} else if (line.match(/<BREAK SOUND PITCH:[ ](\d+)>/i)) {
obj.breakSound['pitch'] = parseInt(RegExp.$1);
} else if (line.match(/<BREAK SOUND PAN:[ ]([\+\-]\d+)>/i)) {
obj.breakSound['pan'] = parseInt(RegExp.$1);
} else if
(line.match(/<CUSTOM BREAK EFFECT>/i)) {
evalMode = 'custom break effect';
} else if
(line.match(/<\/CUSTOM BREAK EFFECT>/i)) {
evalMode = 'none';
} else if
(evalMode === 'custom break effect') {
obj.breakEval = obj.breakEval + line + '\n';
}
}


the code in red i think is this for multi-line note but i not sure
If you're doing it your way

var regexp = /\<synthesis\:\[(.*)\]/

This will cover all text after <synthesis:

it should be

var regexp = /\<synthesis\:\[(.*)\]>/

so that it will stop once it encounters the > character

Not really game breaking for your system, but this is more efficient.

what Yanfly did was:

Enumerate each line of notedata
Check if the line matches any of the tags that he needs to check

So basically, he checked different tags in one go instead of making a new method/function to check each tag. It's actually not a check for multiline tags, but rather a single function check for multiple, completely different tags. The concept will also work for multiline tags too though, but you better find a method to enclose the contents of what you're checking.

That is what the last three checks of yanfly was for, First it checked for the upper tag which denotes the start of the multiline tag, if it finds it, it sets a variable to tell the system that it is now checking a multiline tag. The third line if you see checks if were on multiline mode and performs the correct thing. The second line is for checking the end tag so that the system will now know that we're finished with the multiline tag.

So you can do it like that, Or

On your case, you need to get the part of the data that is inside the <synthesis:> tag first and just enumerate the lines of it to make sure you're getting the correct line since some of the tags you have inside synthesis are pretty common names so multiple systems might be using those same tags.

so basically you'd have something like

var regexp = /\<synthesis\:\[(.*)\]>/
var matchNote = notedata.match(regexp)
if (matchNote not equal to nil, I'm not sure exactly how it's written in JS) {
You do it like how yanfly enumerated per line, but instead of enumerating notedata, you will enumerate matchNote
}

That or you do it like this:

<synthesis_type:>
<synthesis_tabId:>

and so on, so now it's easier to implement the per line checking while also making sure that you won't be fetching the wrong tag/line

Basically, there are multiple ways to do this and it depends on your preferences and which one you find easier to implement.

Personally I hate doing the per line check as I prefer making a retrieval method that retrieves the data everytime I need it so that I can keep it easily working with saved files made before the plugin was made, and also because it's more modular. On the other hand, Yanfly's method is a really efficient one as you avoid checking notes over and over again to match several strings.
Thanks Engr. Adiktuzmiko ^^

i test this and report results 🙂
It could take a lot of testing and bug hunting, but I'm sure you'll get there eventually. I can't help with the specific JS codes that you need as I'm still more of an Ace user but at least the logical flow of things are still the same, especially for regexp matching.

BTW, there are online regexp checkers. You can try those to test out if your regexps will return the correct value. In case you're not with your RM etc.
Edit: The post was written before I saw Engr. Adiktuzmikos post, so it might contain little new.

---

I haven't used javascript much and any experience with regular expressions was achieved using Ruby, so in addition there also might be some differences I am not aware of. 🙂

I don't know if you are familiar with the special characters used in regular expressions, but you can look those up in sources like MDN. I haven't looked around much though, so there might be someone knowing a better source. 🙂

As for your regular expression
var regexp = /\<synthesis\:\[(.*)\]/
, this should work.
You should be able to access RegExp.$1 afterwards to analyze the contents of the captured block. Especially, you'd probably want to separate your arguments by using RegExp.$1.split(",") or something similar.

As an alternative to using , you can be a bit more specific about the contents of said block, separating the arguments beforehand:
/<synthesis:\[(.*?),(.*?),(.*?),(.*?),(.*?)\]>/
The dot matches a single character. *? allows the previous expression to occur multiple times in a row while trying to match as few occurrances as possible. By doing this the game will not try to interpret a comma as part of your argument unless absolutely necessary. Afterwards, you can use RegExp.$1 through RegExp.$5 to access each particular block.

If you want to be more strict and also check the format of your arguments, you could do something like this:
/<synthesis:\[([BN]),(\d+),(\d+),(\-?\d+),(\-?\d+)\]>/
(The first argument must be one of the characters B/N, the others must be a series of digits (0-9). The 4th and 5th argument allows a "-" at the beginning (The ? means that the previous expression is optional)).

Of course this means that any sequence that does not completely match this pattern is ignored.


As for multi-line matches:

Usually, I'd use the . to match any single character. However, according to MDN, the dot does not match linebreaks even in multi-line mode. Instead, [^] (= "any character except <nothing>") should be used to match a random character including newlines.
In order to use your first pattern, you could use this to extract an argument block:
/<synthesis>([^]*?)<\\synthesis>/

You could then search the extracted sequence for matches of your arguments.


In the plugin you posted, the note is instead processed line by line. If one line matches the start of a block, the plugin remembers that. If one line matches the end of a block, the plugin clears the memory of having seen a "start". Any other line is processed as being part of the block if there was a "start" match before.
So you should be correct on your assumption.
also take note of additional regexp terms that you can put after the closing /

like

i -> makes the regexp check not case specific (or was it to make it case specific I kinda forgot)
m -> makes the matching work multilines

for example

<mytag>
line 1
line 2
line 3
</mytag>

if I do

match(/<mytag>(.*)<end_mytag>/)

it actually won't capture my note as a match because it spans multiple lines

but if I do

match(/<mytag>(.*)<end_mytag>/m)

it will now capture my note as a match
@Engr. Adiktuzmiko:
Yes ^^ i use regex101.com for test my regular expression 🙂

@
Another Fen:
Thanks for your explain Another Fen, i have rewrite my regexp ^^

var regexp = /\<synthesis: ([BN]),([0-9]),([0-9]),(\d+),(\d+)\]\>/


your example match on my regexp 🙂
I need just one regexp because my plugin is very long and im lazy xD.

Original thread: https://forums.rpgmakerweb.com/threads/my-regexp-_.77447/