Frostorm

[]D[][]V[][]D
Veteran
Joined
Feb 22, 2016
Messages
2,314
Reaction score
1,940
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,493
Reaction score
8,320
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,314
Reaction score
1,940
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,493
Reaction score
8,320
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

Lots of not good things happening IRL but I'm not gonna let this day end like this. Quote time:
"Success is not final, failure is not fatal: it is the courage to continue that counts." -Winston Churchill

So, keep going, lads. Whatever you do keep going. Until next time.

It's a Spanish devlog don't get scared!. (please)
Q:"Why don't you get a job?"
A: Posting statuses IS my job. It just so happens to not pay and happen periodically over the course of three months.
My new 49" monitor has been dispatched from the warehouse. Will it arrive tomorrow? The day after? I love that we can track packages now, even if it does only tell me when it's left that end and when it's arrived at the local centre. As long as it doesn't end up in Melbourne again, which has happened before ...

Forum statistics

Threads
117,238
Messages
1,105,781
Members
153,402
Latest member
maurosanfi
Top