Many times in RPGMaker MV when creating plugins you’ll want data from the developer about an item, character, etc; we can get that data using note tags.
Here’s an example of a note tag.
Regular expressions are patterns by combining flags and special characters for formatting to get data from text.
- g (Checks all the text in the string, instead of giving up after the first match)
- i (Ignores capital and lowercase letters; considers them equal)
- * (Character can occur 0 or more times)
- + (Character can occur 1 or more times)
- ? (Character can occur 0 or 1 times)
- \s (Matches any space characters: ‘ ‘, ‘\r’, \t’, ‘\l\r’)
- \w (Matches any word character: A-z)
- \d (Matches any digit character: 0 – 9)
- () (Used to capture data from the text; known as a capture group)
Combining the three ideas into a completely wrapped package, we can move on to creating regular expressions for reading note tags.
Here’s an example of a couple for the above screenshot.
Pattern 1 combines ‘\s‘ with ‘‘; this means you can have optional spaces between the characters. Then we have the capture group ‘(\d+.\d*)‘; this means to get any digits optionally followed by a ‘.’ and more digits.
Pattern 2 is the same exact pattern without ‘\s*‘; this means the matching is extremely strict and you can’t have optional spaces.
Now, how do we read note tags effectively?
Here’s an example to read the note tag in the above screenshot from the skills data.
This function goes through each skill in RPGMaker MV, looks at the note box text, and then compares it to our regular expression. If there’s a match, we send the result to the console.
Here’s the result in the RPGMaker MV console.
These are basic tools you’ll be using when constructing regular expressions of reading your own note tags. I hope this helped you. If you think it can help someone else, share it on your favorite platforms.
Have a wonderful day!