What is RegexMatchAt/RegexMatchCount

Get help using Construct 2

Post » Fri Sep 26, 2014 5:06 am

Code: Select all
RegexMatchAt(String, Regex, Flags, Index)
Process the regular expression Regex on String with Flags, and in the list of results, return the entry at Index.

RegexMatchCount(String, Regex, Flags)
Process the regular expression Regex on String with Flags, and return the number of entries in the list of results.

RegexReplace(String, Regex, Flags, Replace)
In String substitute matches for the regular expression Regex (with Flags) with the string Replace. The replacement string can contain the following special characters: $$ (inserts a $), $& (inserts the matched substring), $` (inserts the portion of the string that precedes the matched substring), or $' (inserts the portion of the string that follows the matched substring).

RegexSearch(String, Regex, Flags)
Return the index of the first character in String where a match for Regex with Flags could be found.


Seems useful ! But i don't know what is this...
Please someone post a demo for tell me what is that or how to use? :mrgreen: :mrgreen:
Thankyou!!
B
17
S
7
Posts: 360
Reputation: 2,202

Post » Fri Sep 26, 2014 7:20 am

Regex aka Regular Expressions. Its a big topic. So I'll just give you a small example of the power of what it can do. Google should help if you want to know more

You want to extract the website names from these website addresses, but you don't know what to expect but you know that there is a pattern of "www." and ".com"
http://www.google.com http://www.yahoo.com http://www.scirra.com

So you can use regex!

with a pattern like "@www\.(.*)\.com@"

@@ is the delimiter, it tells you where the pattern starts and ends (you can add flags at the end for matching new lines, ignore case sensitivity etc), but this may only apply to php
\. is escaping full stop
. is match any character
* is match 0 or more any characters

You can test and learn with this tool: http://regexpal.com/
In the top box, enter this:
Code: Select all
www\.(.*)\.com

In the second box, enter this:
Code: Select all
http://www.google.com
http://www.yahoo.com
http://www.scirra.com
B
32
S
6
G
2
Posts: 317
Reputation: 2,801

Post » Fri Sep 26, 2014 7:55 am

IndieKiwi wrote:Regex aka Regular Expressions. Its a big topic. So I'll just give you a small example of the power of what it can do. Google should help if you want to know more

You want to extract the website names from these website addresses, but you don't know what to expect but you know that there is a pattern of "www." and ".com"
http://www.google.com http://www.yahoo.com http://www.scirra.com

So you can use regex!

with a pattern like "@www\.(.*)\.com@"

@@ is the delimiter, it tells you where the pattern starts and ends (you can add flags at the end for matching new lines, ignore case sensitivity etc), but this may only apply to php
\. is escaping full stop
. is match any character
* is match 0 or more any characters

You can test and learn with this tool: http://regexpal.com/
In the top box, enter this:
Code: Select all
www\.(.*)\.com

In the second box, enter this:
Code: Select all
http://www.google.com
http://www.yahoo.com
http://www.scirra.com

seems very complex but powerful
thankyou for your demo!!!!!!
B
17
S
7
Posts: 360
Reputation: 2,202

Post » Fri Sep 26, 2014 8:19 am

IndieKiwi wrote:Regex aka Regular Expressions. Its a big topic. So I'll just give you a small example of the power of what it can do. Google should help if you want to know more

You want to extract the website names from these website addresses, but you don't know what to expect but you know that there is a pattern of "www." and ".com"
http://www.google.com http://www.yahoo.com http://www.scirra.com

So you can use regex!

with a pattern like "@www\.(.*)\.com@"

@@ is the delimiter, it tells you where the pattern starts and ends (you can add flags at the end for matching new lines, ignore case sensitivity etc), but this may only apply to php
\. is escaping full stop
. is match any character
* is match 0 or more any characters

You can test and learn with this tool: http://regexpal.com/
In the top box, enter this:
Code: Select all
www\.(.*)\.com

In the second box, enter this:
Code: Select all
http://www.google.com
http://www.yahoo.com
http://www.scirra.com

but...can you please make a screen shot for me?
i know how to use Regex now but not in C2
this not working
Code: Select all
RegexMatchCount("http://www.google.com http://www.yahoo.com http://www.scirra.com","www\.(.*)\.com","")
 

:roll: :roll: :roll:
Thankyou sososooss much again
B
17
S
7
Posts: 360
Reputation: 2,202

Post » Fri Sep 26, 2014 9:12 am

fongka2 wrote:but...can you please make a screen shot for me?
i know how to use Regex now but not in C2
this not working
Code: Select all
RegexMatchCount("http://www.google.com http://www.yahoo.com http://www.scirra.com","www\.(.*)\.com","")
 

:roll: :roll: :roll:
Thankyou sososooss much again


I haven't used it in C2 yet, its on my todo list :lol:

Your using RegexMatchCount which is a count method, so with the example, it should return int 3.

If that doesn't work can u try using "@www\.(.*)\.com@"? Not sure if C2 needs the delimiters, in this case i am using "@" just to keep it simple, i won't go too much into it

Note: RegexMatchAt and RegexReplace would be more useful than RegexMatchCount

With RegexMatchAt, it only would return one result so you should do each website one at a time. For example, a list of website urls in a loop

One last thing i forgot in my last post is the brackets (). inside is what you want to capture. so if you had "www.google.com" with regex pattern "www\.(.*\.com)" RegexMatchAt will return "google.com"
B
32
S
6
G
2
Posts: 317
Reputation: 2,801

Post » Fri Sep 26, 2014 10:59 am

IndieKiwi wrote:
fongka2 wrote:but...can you please make a screen shot for me?
i know how to use Regex now but not in C2
this not working
Code: Select all
RegexMatchCount("http://www.google.com http://www.yahoo.com http://www.scirra.com","www\.(.*)\.com","")
 

:roll: :roll: :roll:
Thankyou sososooss much again


I haven't used it in C2 yet, its on my todo list :lol:

Your using RegexMatchCount which is a count method, so with the example, it should return int 3.

If that doesn't work can u try using "@www\.(.*)\.com@"? Not sure if C2 needs the delimiters, in this case i am using "@" just to keep it simple, i won't go too much into it

Note: RegexMatchAt and RegexReplace would be more useful than RegexMatchCount

With RegexMatchAt, it only would return one result so you should do each website one at a time. For example, a list of website urls in a loop

One last thing i forgot in my last post is the brackets (). inside is what you want to capture. so if you had "www.google.com" with regex pattern "www\.(.*\.com)" RegexMatchAt will return "google.com"

Its working
i forgot add "Flag"
but for now i only can add Flag*1
I don't know how to use Flag>1
B
17
S
7
Posts: 360
Reputation: 2,202

Post » Fri Sep 26, 2014 2:50 pm

C2 use Javascript syntax for its Regex. Delimiters are "^" to match the beginning of a string (or line for multiline) and "$" for the end.

Be aware though that "^www\.(.*)\.com$" won't find a match in "http://www.google.com", since the string doesn't begin with "www".

Regex works great with C2, but it lacks one important thing, there is no capture group support, so "www\.(.*\.com)" will actually match "www.google.com" and not only "google.com" in the string "http://www.google.com". It would be great to be able to do something like RegexMatchAt(0).Groups(0) or something...
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Tue Sep 30, 2014 9:12 pm

Magistross wrote:C2 use Javascript syntax for its Regex. Delimiters are "^" to match the beginning of a string (or line for multiline) and "$" for the end.

Be aware though that "^www\.(.*)\.com$" won't find a match in "http://www.google.com", since the string doesn't begin with "www".

Regex works great with C2, but it lacks one important thing, there is no capture group support, so "www\.(.*\.com)" will actually match "www.google.com" and not only "google.com" in the string "http://www.google.com". It would be great to be able to do something like RegexMatchAt(0).Groups(0) or something...

if = "name(id):hello!"
may i ask,if i wanna to take "id"
what should i do @ C2 please?
B
17
S
7
Posts: 360
Reputation: 2,202

Post » Tue Sep 30, 2014 9:49 pm

If your input string is "name(id):hello!" ?

Not entirely sure I understand your question. :\
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Tue Sep 30, 2014 10:51 pm

Magistross wrote:If your input string is "name(id):hello!" ?

Not entirely sure I understand your question. :\

I'm making a chatroom app
here is i use mid&find
mid(Function.Param(0),find(Function.Param(0),"(")+1,find(Function.Param(0),"):")-find(Function.Param(0),"(")+1)
function.param(0)=username(userid):xxxxxx (eg:fongka2(fongka2):hello!)
B
17
S
7
Posts: 360
Reputation: 2,202

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 16 guests