String.match confusion?

Isabella Ava

Veteran
Veteran
Joined
Sep 13, 2016
Messages
635
Reaction score
756
First Language
English
Hi guys, i having a confusion about how string.match() function work.
I saw inside of Yanfly item core, he check for a <TEXT COLOR: x> note match like this:
line.match(/<(?:TEXT COLOR):[ ](\d+)>/i)
but why ?:
it should work without ?: but why did he include it?
if it for checking zero or one of : shouldn't he wrote :? instead?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
? means 0 or 1. And : is an empty symbol. Yanfly uses it to allow people to type it in any way among:
<text color: 5>, < text color: 5>, <text color:5> or < text color:5>.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
It's not mentioned in too many places, took me a bit to find it myself :D
 

Isabella Ava

Veteran
Veteran
Joined
Sep 13, 2016
Messages
635
Reaction score
756
First Language
English
Wow that true. I had read on w3school & searched google but it didn't mention about this.
That's weird : | oh right, there is something more that trouble me that i want to ask @Poryg
Why match(/<C/i) didn't work?
I mean i have this str = <CT>
i tried str.match(/</i) and str.match(/CT/i) - both worked
but when i tried /<C/i or /<CT>/i it returned nothing. : |
do you know why?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Perhaps < is a code as well? Try <:C if you want. I have seriously no idea though :D
 

Isabella Ava

Veteran
Veteran
Joined
Sep 13, 2016
Messages
635
Reaction score
756
First Language
English
<:C didn't return anything too though. : | maybe you're right. No one mentioned about this :|
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
Tried both in Ruby and JS, both works though.
Screenshot_202.jpg
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
in that case maybe she has it wrong somehow :D
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
@Isabella Ava you tested it in a browser which read HTML tag. So, of course, an incomplete tag like '<' with missing '>' as end can't show up. Even if it's complete <CT> you couldn't even show it in the browser because the tag is unknown.

I usually use https://repl.it/ to test stuff
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
No, it doesn't have a problem. <> are html tags, while just < is not.

Edit: Ninja'd :D

try alert(res). You'll see it shows.
 

Dr.Yami

。◕‿◕。
Developer
Joined
Mar 5, 2012
Messages
1,003
Reaction score
757
First Language
Vietnamese
Primarily Uses
Other
The ?: means the group inside bracket ( ) won't be captured, so the first element in returned match in your example (ignore the match[0] is the whole string) will be the number
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,867
Messages
1,017,061
Members
137,575
Latest member
akekaphol101
Top