mIRC Homepage
Posted By: silver2ksurfer cut all after a word - 26/08/22 05:32 PM
Hi Community,

i search for a simple cut in $1

Sample:
All is fine and we have no Problems.
This is a Sample we want nothing.

I will cut all after "we"

Output:
All is fine and we
This is a Sample we


Can anyone help me?

Big THX.
Posted By: maroon Re: cut all after a word - 26/08/22 09:08 PM
//tokenize 32 All is fine and we have no Problems | var -s %find $findtok($1-,we,1,32) | if (%find) var -s %find $gettok($1-,1- %find,32)
Posted By: silver2ksurfer Re: cut all after a word - 28/08/22 08:10 AM
Big THX. Working good. laugh
Posted By: JohnEricNO Re: cut all after a word - 28/08/22 10:02 PM
An alternate method is to use $regex:

Cut off after the first we:
//noop $regex(All is fine and we have no Problems., (^.*?we)) | echo -a $regml(1)

In more general terms in a remote:
//noop $regex($1-, (^.*?we)) | echo -a $regml(1)
Posted By: maroon Re: cut all after a word - 30/08/22 01:42 AM
it depends if they want case-sensitive or not. My example was case-insensitive and would find the word WE unless using $findtokcs instead of $findtok.

However your regex finds the 'we' string within words

//echo -a $regex(oh what a swell weekend we had!, (^.*?we)) | echo -a $regml(1)

result: oh what a swe

//echo -a $regex(oh what a horrible weekend we had!, (^.*?we)) | echo -a $regml(1)

result: oh what a horrible we

this regex finds 'we' has a complete word:

//echo -a $regex(oh what a swell weekend we had!, (^.*?\bwe\b)) | echo -a $regml(1)

result: oh what a swell weekend we
Posted By: JohnEricNO Re: cut all after a word - 30/08/22 02:19 AM
In that case, we can use \b for word boundary and /i for case-insensitive:

//noop $regex(All is fine and we have no Problems. , /(^.*?\bwe\b)/i) | echo -a $regml(1)
result: All is fine and we

//noop $regex(All is fine and WE have no Problems. , /(^.*?\bwe\b)/i) | echo -a $regml(1)
result: All is fine and WE
Posted By: maroon Re: cut all after a word - 01/09/22 11:46 PM
Sometimes it's not always a good idea to throw regex at a problem if there are other tools that do the job just fine.

Wims pointed out that \b isn't actually what me and you and a dog named boo think is a word boundary. In regex, there are 63 things that can be ina word - alphanumeric or underscore, and this may not be getting them what they want.

//noop $regex(and it's we-we-western theme here at the costume party! , /(^.*?\bwe\b)/i) | echo -a $regml(1)

result: and it's we

So if OP isn't happy with what $gettok's idea of a word "things between spaces", they need to give some examples of what false-positive or false-negative they're encountering.
© mIRC Discussion Forums