Frostorm

[]D[][]V[][]D
Veteran
Joined
Feb 22, 2016
Messages
2,285
Reaction score
1,922
First Language
English
Primarily Uses
RMMV
Hi, I've been learning a lot of JS lately, but 1 thing I haven't been able to understand clearly is the symbols for searching terms. Examples:
  • stuff.match(/(\(.*\))/i)
  • stuff.match(/(circle|line|square|cross)\((.+)\)/i)
It's those "*", "+", etc...that I don't understand...
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,485
Reaction score
8,275
First Language
Indonesian
Primarily Uses
RMVXA
This might help

* means match with the previous character, none or more.
+ means match with the previous character, one or more.
Since you're using a greedy match, (using dot), it matches with everything (except newline feed).

In your example, /(\(.*\))/i match with the following string
  • (asdfghg)
  • (12345)
  • (asd2345)
  • ()
But if you turn /(\(.*\))/i to /(\(.+\))/i, it won't match with empty parenthesis. It has to have something within the parenthesis.
 

Frostorm

[]D[][]V[][]D
Veteran
Joined
Feb 22, 2016
Messages
2,285
Reaction score
1,922
First Language
English
Primarily Uses
RMMV
Hmm...I get 2 errors on the site u linked using the same code I posted above. The code works in game (I'm not the author of the plugin containing the Regex) so idk why it says I need to add more backslashes.
1635200960283.png

Btw, what if I want it to search/match anything that contains "e."? As in the letter "e" followed by a period, or does it not search for periods?

Edit: Nvm, I figured it out. Thx for that website, it was super helpful! :D
 
Last edited:

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,485
Reaction score
8,275
First Language
Indonesian
Primarily Uses
RMVXA
Good that you have found your answer, but I will leave my answer here for a sake of others.

Btw, what if I want it to search/match anything that contains "e."? As in the letter "e" followed by a period, or does it not search for periods?
Period (.) in regex is used for the greedy matches. If you want an exact match with it, use \.

The confusing part of REGEX is sometimes it isn't consistent. See, to "neutralize" the matching token, you have to put \, but the opposite is also true because you need \d to match with any number. Putting d on its own is just an exact match with the character d.
 

Latest Threads

Latest Posts

Latest Profile Posts

I'm new to rpgmaker mv, link me some good stuff to learn.
Finally, I have graduated from college and now I can put a lot more work into my game, after having not worked on it for the better part of a year.
post so i can change my profile picture ^^
Creating Some art for a fighter game.

Finally was able to record the rest of the game demo! I added some edits here and there, this is why it takes me so long to do stuff cuz I find a problem and have to fix it asap. x.x
Game: https://dj990j.itch.io/region-of-mythos

Forum statistics

Threads
117,062
Messages
1,104,208
Members
153,026
Latest member
sleezyretro
Top