mIRC Home    About    Download    Register    News    Help

Print Thread
Return variable position? #208144 14/01/09 11:56 AM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline OP
Babel fish
OP Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
I'm trying to find the position of a variable i want.

I know it has certain characters in it al the time but it always is on a different position.

As i normaly would do tokenize 32 $strip($1-) and mark position as $5 for example it now fails.

on *:TEXT:*:#:{
tokenize 32 $strip($1-)
if ($regex($1-,/(.*?)\-/i) > 0) {
var %location = ?
}
}

Another thing, as i just copy-pasted the regex, if anyone can explain what this means?
($regex($1-,/(.*?)\-/i) > 0)

Re: Return variable position? [Re: ots654685] #208154 14/01/09 03:04 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Quote:
Another thing, as i just copy-pasted the regex, if anyone can explain what this means?
($regex($1-,/(.*?)\-/i) > 0)


I know (.+?) means to match any character 1 or more times lazily.

In that line of above regex code will match the symbol - more than once.

A backslash is used to escape special characters literally.

Re: Return variable position? [Re: ots654685] #208157 14/01/09 04:06 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
The regex above will capture text close to (but not exactly like) a "$gettok($1-,1,45)":
- it will match the first "-"char in $1- (found a match, return "1", the if-statement is true now)
- and it will capture all the text before that matching char if there is text preceding the char (you can refer to this text via $regml(1). the if-statement will be true if no text preceds the "-"char though).

As I assume a combination of token identifiers and/or other text identifiers like $pos may be sufficient, please provide an example on how you want to find/match - I'm not sure what you want to find:
- the position of a specific char in the string of text?
- the start and end position of some text?
- a relative position of some text?
- the text itself?

smile

Re: Return variable position? [Re: Horstl] #208161 14/01/09 05:58 PM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline OP
Babel fish
OP Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
That regex thing is clear now, thanks

For my intentional problem.

An exmaple.

first line ($6):
"some text blablabla blablabla blablabla ITEM/I/WANT/THE/POSITION/FROM blablabla blablabla blablabla"

but it can also be this ($4) and different text.
"some text blablabla THIS/POSITION/I/WANT blablabla blablabla"

1 thing i know for sure is that it has /'s in it or other characters i can filter/grab with regex (it won't be "uber" regex but i'll tweak it along the way).

But how to use/convert it as a variable like $3 or $6 ?


Re: Return variable position? [Re: ots654685] #208162 14/01/09 06:08 PM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Do you mean this?
Code:
tokenize 47 $1-

Then...
$1 = some text blablabla THIS
$2 = POSITION
$3 = I
$4 = WANT blablabla blablabla

Though for this exercise it's probably counter-productive. >.>

You probably want $matchtok. If the string with the slash(es) in it contains no spaces you can simply use $matchtok($1-,/,1,32). If it does, you can first return the number of matches with $matchtok($1-,/,0,32) and then return all matches.

$findtok($1-,$matchtok($1-,/,1,32),1,32) would return the position (tokenized by the default space character) of the first match.

Last edited by 5618; 14/01/09 06:18 PM.
Re: Return variable position? [Re: ots654685] #208168 14/01/09 09:47 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
If you want to do something with the Nth space-delimited token that contains a slash char, I'd use token identifiers like 5618 suggested (N is 1 in this example):
Code:
var %text = some text here this-token-contains-a/slash more text here 
if ($matchtok(%text,/,1,32)) {
  - do something with $v1 -
}

To me, this is more handy than an equivalent regex:
Code:
var %text = some text here this-token-contains-a/slash more text here
if ($regex(%text,/(\S*\/\S*)/)) {
  - do something with $regml(1) - 
}
(check like for a space-delimited token: "capture the first occurance of zero or more non-space chars, followed by a slash (using the "\"char to escape the "/" metachar), followed by zero or more non-space chars").