What is RegexMatchAt/RegexMatchCount

0 favourites
  • 11 posts
  • 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.[/code:1nbjwm8u]
    
    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?  
    Thankyou!!
  • 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:

    www\.(.*)\.com[/code:1xfoz14q]
    In the second box, enter this:
    [code:1xfoz14q]
    http://www.google.com
    http://www.yahoo.com
    http://www.scirra.com
    [/code:1xfoz14q]
  • 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:

    www\.(.*)\.com[/code:2x5tn8ln]
    In the second box, enter this:
    [code:2x5tn8ln]
    http://www.google.com
    http://www.yahoo.com
    http://www.scirra.com
    [/code:2x5tn8ln]
    

    seems very complex but powerful

    thankyou for your demo!!!!!!

  • 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:

    www\.(.*)\.com[/code:2qdnas4l]
    In the second box, enter this:
    [code:2qdnas4l]
    http://www.google.com
    http://www.yahoo.com
    http://www.scirra.com
    [/code:2qdnas4l]
    

    but...can you please make a screen shot for me?

    i know how to use Regex now but not in C2

    this not working

    RegexMatchCount("http://www.google.com http://www.yahoo.com http://www.scirra.com","www\.(.*)\.com","")
     [/code:2qdnas4l]
     <img src="{SMILIES_PATH}/icon_rolleyes.gif" alt=":roll:" title="Rolling Eyes">  <img src="{SMILIES_PATH}/icon_rolleyes.gif" alt=":roll:" title="Rolling Eyes">  <img src="{SMILIES_PATH}/icon_rolleyes.gif" alt=":roll:" title="Rolling Eyes">
    Thankyou sososooss much again
  • but...can you please make a screen shot for me?

    i know how to use Regex now but not in C2

    this not working

    RegexMatchCount("http://www.google.com http://www.yahoo.com http://www.scirra.com","www\.(.*)\.com","")
     [/code:1k2oog3c]
     
    Thankyou sososooss much again
    

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

    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"

  • >

    > but...can you please make a screen shot for me?

    > i know how to use Regex now but not in C2

    > this not working

    >

    RegexMatchCount("http://www.google.com http://www.yahoo.com http://www.scirra.com","www\.(.*)\.com","")
    >  [/code:yfxjdn64]
    >  
    > Thankyou sososooss much again
    > 
    
    I haven't used it in C2 yet, its on my todo list   
    
    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

  • 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...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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?

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

    Not entirely sure I understand your question. :\

  • 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!)

  • Oh, then I guess you want what's between the parenthesis ? Try this :

    RegexMatchAt(Function.Param(0), "[^\(]+(?=\))", "", 0)[/code:2fqcyfvw]
    It will match the first occurence of multiple characters that does NOT contain an opening parenthesis and ends with a closing parenthesis, without including it in the match, hence the positive lookahead "(?=\))".
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)