Need some notetag help

My item notetag:

<recipe> <image "soup.png">  <ingredient 21 3>  <ingredient 22 5>  <ingredient 23 2></recipe>Checking if it contains a recipe tag is easy:

#RECIPE_TAG = <recipe>class RPG::Item  def is_recipe?        return note =~ /#{Nap::RECIPE_TAG}/  endendBut I need to search the recipe-notetag contents somehow line by line (ignoring leading spaces) and get the image value as well as the 2 numbers per ingredient. I tried a couple of methods but I kept failing and I just suck at regex every single time. I don't necessarily need the full code but a few hints in the right direction would be nice.
http://rubular.com/

that little editor helps me out a lot
I already used that one 🙂 .

Btw, I use this:

/<([^>]*)>/to get the values between the <>. But I must somehow ensure that the ingredient and image matches are within the <recipe> and </recipe> tags AND scan them one by one.

This does not work:

<recipe>([^>]*)</recipe>And this neither:

Code:
<recipe>(.*?)<\/recipe>
This is a problem I would like to find a better solution for, especially with my use of "extended notetags" where data is specified as option-value pairs, where each option is optional

<notetag>name1: value1name2: value2name3: value3</notetag>Currently I just parse the thing, assuming option pairs are separated by line-breaks and the (name, value) pair is separated by a common delimiter.The regex I use is of the form

/<notetag>(.*?)<\/notetag>/imThis would correctly identify separate note-tags

Code:
<notetag>option: first tag</notetag><notetag>option: second tag</notetag>
http://rubular.com/r/NNDABgPZmuYou can use this as well, if the options are fixed.

/<notetag>(?:.*?)(?:name1🙁.*?))?(?:name2🙁.*?))?(?:name3🙁.*?))?<\/notetag>/imWhich looks like
Code:
<notetag>name1: arg1name2: arg2name3: arg3</notetag>
You can omit options, but you can't order them any way you wantValid:

<notetag>name1: arg1name3: arg3</notetag>Invalid:
Code:
<notetag>name3: arg3name1: arg1</notetag>
http://rubular.com/r/hTquDPXWqoThis can probably be cleaned up but I don't know how.

The first (.*?) is used only to capture new-lines.
Thanks. I got it working now. I also changed my notetags to match yours. It's much easier. Regexing xml = no fun anyway.

*mumbles something about annoying regex 😛 *
Honestly I don't like parsing the thing line by line when the regex could do it for me

Let's remove leading/trailing spaces in the values for this

/<notetag>(?:.*?)(?:name1:\s*(.*?)\s*)?(?:name2:\s*(.*?)\s*)?(?:name3:\s*(.*?)\s*)?<\/notetag>/im(rubular automatically trims them)Looks really ugly at this point

http://regex101.com/r/vT9mR5 (this isn't Ruby regex engine, but it tells you what the regex means)
I used 1 each loop for the ingredients and none for the image. Yes it can be done using regex.

Oh nice link, I didn't know that one yet 🙂 .

Original thread: https://forums.rpgmakerweb.com/threads/need-some-notetag-help.18819/