mIRC Homepage
Posted By: BraveHeart73 $Regex Data Capture Help - 27/07/22 11:04 AM
Hi.
I want to capture data with @ & and ~ symbols in it. I made some attempts but no results.

//echo -a $regsubex(@Gandalf %Legolas @Brave,/\[@&~]/g,\1) = Return : @Gandalf @Brave : OK very good.

For example, there is no problem with this first command
-----
However, when there is a name with no symbols, the regex catches it as well. :S

Sample: //echo -a $regsubex(@Gandalf Legolas BraveHeart @Brave,/\[@&~]/g,\1) : Return: @Gandalf Legolas BraveHeart @Brave

Whereas it should only give names containing @, & and ~.


In short, how can I catch names containing @, & and ~ symbols with regex?
Posted By: Wims Re: $Regex Data Capture Help - 27/07/22 09:46 PM
Hey,

$regsubex(@Gandalf %Legolas @Brave,/\[@&~]/g,\1) removes "%legolas" because it's a variable name and it evaluates to $null, not because of the regex you're doing. your expression /\[@&~]/g is invalid and result in mIRC returning the original input string, and you're using \1 but your expression has no capturing group in the expression with (), so it doesn't make sense anyway.

Your second example is all the same, except there's no variable, so the original input string is returned.

If you want to 'remove' token seperated by space in the input string, you would use a pattern such as /(?<=^| )[@&~][^ ]+(?=$| )/g, $regsubex(@a c @a d @a,/(?<=^| )[@&~][^ ]+(?=$| )/g,) returns "c d"
Posted By: BraveHeart73 Re: $Regex Data Capture Help - 28/07/22 08:29 PM
@Wim'ler Thank you for the answer.

However, it was the opposite of what I wanted. Maybe we had a communication problem because my English is not enough.

What I want is to display the parts with @ & % ~ .

So regex command response ;

$regsubex(@a b %c d @e f, > Return : @a %c @e I want it this way.
Posted By: Wims Re: $Regex Data Capture Help - 28/07/22 09:21 PM
If you pass %c manually to regsubex it's evaluated, for the test you need to get %c plain text with % $+ c for example.

You can use the following pattern to achieve what you want: $regsubex(@a @r b &u i o % $+ c d @e f ~g ,/(?:((?:^| )[@~&%][^ ]+(?=$| ))|(?: |^)[^ ]+(?= |$))/gF,\1\2)
Posted By: BraveHeart73 Re: $Regex Data Capture Help - 29/07/22 12:09 PM
Thank you for the answer.


echo -a $regsubex(@a @r b &u i o d @e f ~g ,/(?:((?:^| )[@~&][^ ]+(?=$| ))|(?: |^)[^ ]+(?= |$))/gF,\1) : Return : @a @r &u &u @e @e @e @e ~g ~g

shows the same characters more than once :S

it should have been like this: Return : @a @r &u @e ~g

??
Posted By: Wims Re: $Regex Data Capture Help - 29/07/22 03:55 PM
Use the code provided in the post, all of it. not 92% of it.
Posted By: Wims Re: $Regex Data Capture Help - 29/07/22 05:11 PM
Hum, in fact you only missed the \2 from the replacement.. and that \2 came from an earlier solution, it's not required anymore in the current solution, but having it is not a problem and will work the same, so it should have worked for you.
Quote
echo -a $regsubex(@a @r b &u i o d @e f ~g ,/(?:((?:^| )[@~&][^ ]+(?=$| ))|(?: |^)[^ ]+(?= |$))/gF,\1) : Return : @a @r &u &u @e @e @e @e ~g ~g
This returns the correct result, it does not return what you said, which version of mIRC are you using?
Posted By: BraveHeart73 Re: $Regex Data Capture Help - 29/07/22 09:12 PM
Thank you for the answer.

mIRC version 6.35
-
It still shows the characters more than once unfortunately.
Posted By: Wims Re: $Regex Data Capture Help - 30/07/22 01:05 AM
You get incorrect result because you're using 6.35. Here is a fix for 6.35:

//echo -a $regsubex(@a @r b &u i o d @e f ~g ,/(?:((?:^| )[@~&][^ ]+(?=$| ))|(?: |^)[^ ]+(?= |$))/g,\t)

The pattern js the same, you only replace \1 with \t (same as $regml(\n)).
© mIRC Discussion Forums