mIRC Home    About    Download    Register    News    Help

Print Thread
#270687 26/08/22 05:32 PM
Joined: Mar 2020
Posts: 4
S
Self-satisfied door
OP Offline
Self-satisfied door
S
Joined: Mar 2020
Posts: 4
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.

Joined: Jan 2004
Posts: 1,835
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,835
//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)

Joined: Mar 2020
Posts: 4
S
Self-satisfied door
OP Offline
Self-satisfied door
S
Joined: Mar 2020
Posts: 4
Big THX. Working good. laugh

Joined: Dec 2011
Posts: 17
J
Pikka bird
Offline
Pikka bird
J
Joined: Dec 2011
Posts: 17
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)

Joined: Jan 2004
Posts: 1,835
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,835
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

Joined: Dec 2011
Posts: 17
J
Pikka bird
Offline
Pikka bird
J
Joined: Dec 2011
Posts: 17
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

Joined: Jan 2004
Posts: 1,835
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,835
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.


Link Copied to Clipboard