mIRC Homepage

Return variable position?

Posted By: ots654685

Return variable position? - 14/01/09 11:56 AM

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)
Posted By: Tomao

Re: Return variable position? - 14/01/09 03:04 PM

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.
Posted By: Horstl

Re: Return variable position? - 14/01/09 04:06 PM

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
Posted By: ots654685

Re: Return variable position? - 14/01/09 05:58 PM

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 ?

Posted By: 5618

Re: Return variable position? - 14/01/09 06:08 PM

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.
Posted By: Horstl

Re: Return variable position? - 14/01/09 09:47 PM

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").
© 2022 mIRC Discussion Forums