Regex, I think I don't get it

Get help using Construct 2

Post » Wed Apr 23, 2014 6:01 pm

I wanted to learn to use regex, since I think it can be a real useful tool, so I begin with something basic, however, something feels wrong to me.

Right now I have a Text that displays at the start of layout the result of this expression:

RegexMatchCount("Create Create cReate", "Create", "i")

It returns 1, I'd expect it to return 3, but it doesn't and I don't understand why, I mean, Create is located twice, and cReate should also be counted too due to the "i" flag.

Can someone help me understand?
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093

Post » Wed Apr 23, 2014 6:27 pm

I haven't really played with reg expressions in construct but it sounds like its doing a test() and not a match()
The first returns true/false where the second would return an array with the matched text

Image
Last edited by Noncentz705 on Wed Apr 23, 2014 6:54 pm, edited 1 time in total.
B
10
S
2
G
1
Posts: 202
Reputation: 1,545

Post » Wed Apr 23, 2014 6:47 pm

Try with the g flag, to make the search global.
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Wed Apr 23, 2014 7:00 pm

adding the "g" flag solved it, thanks ^both of you for your help
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093


Return to How do I....?

Who is online

Users browsing this forum: DjowG, ramyaswetha and 5 guests