Frostorm

[]D[][]V[][]D
Veteran
Joined
Feb 22, 2016
Messages
2,788
Reaction score
2,232
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
7,164
Reaction score
10,500
First Language
Indonesian
Primarily Uses
N/A
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,788
Reaction score
2,232
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
7,164
Reaction score
10,500
First Language
Indonesian
Primarily Uses
N/A
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

Today I released one of my favourite tutorials :3 Learn how to make consistent yet interesting towns!
As always, I am very open for feedback!
1679673622425.png
This girl is jealous because I haven't drawn her again in months.
Fr_RrgwaUAAafNa

New sprites in my project!
Updating my stream thumbnail collection here Streaming more game dev in 30 minutes or so. :LZSexcite:

Programming languages are amazing.

Someone needed help with a problem in C#. I've got 0 experience in C#. I read 0 lines of their code. I only knew what they wanted to do. I wrote a completely generic code in Javascript containing the generic answer. But they understood what I was doing and translated that to their code. 20 seconds later, problem solved.

Forum statistics

Threads
129,815
Messages
1,205,449
Members
170,931
Latest member
uandai
Top