Frostorm

[]D[][]V[][]D
Veteran
Joined
Feb 22, 2016
Messages
2,338
Reaction score
1,951
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,494
Reaction score
8,322
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,338
Reaction score
1,951
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,494
Reaction score
8,322
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

aww man, color hex code #C4C4C4 doesn't work for the tint value in this scene I need something darker, which stinks just because I liked that one it was my favorite plastic explosive three times...#696969 (nice) should work better (WHY IS MY BRAIN LIKE THIS)
Tell it to me straight, doc. If I've been trying to piece together a "shorter" game to learn stuff outside of game jams... am I just running away from my WIP? :v
Well, I've got a party tomorrow, and my friends are coming over. I wanted to work a bit on the Fandom Scouts assets so I can be ready when that update arrives... in other news, Pizza Time Horror is getting a second teaser, and it shows Cabaret Helen's last performance before the location closed.
Also who used to be scared of Chuck E as a kid? I was! Now I love him!
The new cards and what they do:

(I am clearly not a youtuber... Haha)

Forum statistics

Threads
117,282
Messages
1,106,102
Members
153,457
Latest member
kappaclap
Top