Frostorm

[]D[][]V[][]D
Veteran
Joined
Feb 22, 2016
Messages
2,287
Reaction score
1,924
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,491
Reaction score
8,306
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,287
Reaction score
1,924
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,491
Reaction score
8,306
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 Profile Posts

I'm just so close to replacing LUK with a different stat, maybe DEX but we'll see.
Slapped together a title screen and working on some dungeon clutter + portraits for Dubhghaill and Einar. Usual CW for minor body horror wrt Einar
QVLJIgD.png

OaPcYUy.png

r55FiUJ.png

EIgO94y.png
cT1V4nb.png
>studying for months for an exam
>does exam
>waits 3 months for the results to come out
>me trying to login, incorrect password
>I get recovery password
>me trying to login, incorrect password

What the heck. As a son of a Karen, I'm going to file a few complaints.
Apparently Amazon Prime users get free Genshin Impact stuff like primogems and whatnot every month, but I'm not sure I ever want to fall into the abyss of F2P ever again.

Forum statistics

Threads
117,149
Messages
1,104,971
Members
153,229
Latest member
jimproringtones
Top