How to use Regex?

Get help using Construct 2

Post » Sat Aug 17, 2013 3:52 pm

OK, figured it out.
1) you need flag = "g"
2) MatchAt works on the index of the match. You'll need to iterate by using MatchCount to build the string back up, if that's what you want.

RegexTesterblackhornet2013-08-17 16:45:26
ImageImageImage
B
71
S
19
G
179
Posts: 3,478
Reputation: 102,672

Post » Sat Aug 17, 2013 6:36 pm

Ah, the "g" flag does help. Why use RegexMatchAt() and then rebuild the string when you can just use RegexReplace() where everything is done in one call?

This now removes all numbers and not just the first number.
RegexReplace("Hello123", "\d", "g", "")
B
85
S
27
G
85
Posts: 5,062
Reputation: 57,858

Post » Mon Aug 19, 2013 7:03 am

@blackhornet

Nice! It worked like a charm, thanks! :D

@R0J0hound

Thanks! It worked, I think Regex is great to validate forms such as e-mail, telephone number, etc.

I would keep this thread alive if we can add some examples to use regex for all purposes.
B
91
S
31
G
29
Posts: 3,129
Reputation: 27,789

Post » Sat Sep 21, 2013 6:33 am

Wow this is awesome! I was looking for a way to strain out certain text from the user media speech recognition feature and founf regex in system expressions. I searched on forum of course and found here where i tested blackhornet's capx with

http://regexlib.com/CheatSheet.aspx

and got all excited. the cheat sheet helped me put what i wanted in the regex textbox. I was a little confused about flag "g" i see that it might be referring to global, like what is entirely in the input textbox... still not sure tho
B
3
Posts: 7
Reputation: 489

Post » Sat Sep 21, 2013 6:46 am

so now im trying to match everything but "Hello" and "World" so to clarify i want output to read Hello World

(Hello) worked for just Hello... step one lol
B
3
Posts: 7
Reputation: 489

Post » Sat Sep 21, 2013 6:50 am

Hello|World = HelloWorld
B
3
Posts: 7
Reputation: 489

Previous

Return to How do I....?

Who is online

Users browsing this forum: dmrev, DutovLoppa, kototouchdown, mekonbekon, newt, OddConfection, VnM2016 and 10 guests