regexmircusernametoken

get onlye name of string removing tags using regex mirc?


i'm trying to catch only the nickname of a usernames on mirc usign regex but i cant catch this is the data which i want take the username

and in involve this regex code:

/^\x3a(:?(\[\w+\])?(\[\s\w+\s\]?))\s?(\w+)/i

Here is on regexer: Regexer

I would like get the username in Group 1.

so any body have an idea to catch this situations?

if ($regex(info,$1-,/^\x3a(?::?(?:\[\w+\])?(?:\[\s\w+\s\]?)?)?\s?(\w+) (CHAT) (#\S+) \x3a([\x21])(hi|test)( |$)/i)) {
echo * NickName: $regml(info,1)
echo * Method: $regml(info,2)
echo * Channel: $regml(info,3)
echo * Symbol: $regml(info,4)
echo * Trigger: $regml(info,5)  }

:[ Tag ] Xs_user CHAT #test_channel :!hi <- not work!
:madhu CHAT #test_channel :!hi <- this works

so in need to take only username to can compare if nick is operator of channel.


Solution

  • Add two more ? to make (:?(\[\w+\])?(\[\s\w+\s\])) and (\[\w+\])?(\[\s\w+\s\]?) groups optional:

    ^\x3a(:?(\[\w+\])?(\[\s\w+\s\]?)?)?\s?(\w+)
                                    ^ ^
    

    See the regex demo. The user name will be in Group 4 if you use this regex.

    To get the user name into Group 1, use non-capturing groups for all groupings you are not interested in by adding ?: after opening (:

    ^\x3a(?::?(?:\[\w+\])?(?:\[\s\w+\s\]?)?)?\s?(\w+)
          ^^   ^^          ^^   
    

    See this regex demo