From WikiChip
Difference between revisions of "mirc/wildcard"
< mirc

(Removed unnecessary <pre> tags)
 
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{mIRC Guide}}
+
{{mirc title|Wildcards}}
 
 
 
Wildcard characters are special characters that are interpreted when comparing text.
 
Wildcard characters are special characters that are interpreted when comparing text.
  
Line 8: Line 7:
 
* & - matches a whole word if used alone
 
* & - matches a whole word if used alone
  
For example the expression "t*s a *?t" matchtes the string "this is a text"
+
For example the expression "t*s a *?t" matches the string "this is a text"
  
If & is not used alone it matches the plain text '&' character. It also doesn't match $chr(32)
+
If & is not used alone it matches the plain text '&' character
 +
 
 +
'''Note''': It also doesn't match $chr(32) if used to match a whole word, see below
  
 
"test &" matches "test this" or "test that"
 
"test &" matches "test this" or "test that"
Line 20: Line 21:
 
"test th&s" matches only "test th&s"
 
"test th&s" matches only "test th&s"
  
"test &" doesn't match "test $chr(32)"
+
"test &" doesn't match "test $chr(32)" (consider $chr(32) to be evaluated here)
  
Be careful when using the & wildcard character inside /if or $iif, it could be interpreted as the & bitwise operator:
+
Be careful when using the & wildcard character inside /if (and the like: $iif, /while, /elseif) it could be interpreted as the & bitwise operator:
  
 
<source lang="mIRC">if (test & iswm test this)</source>  
 
<source lang="mIRC">if (test & iswm test this)</source>  
Line 28: Line 29:
 
<source lang="mIRC">if ($(test &) iswm test this)</source>
 
<source lang="mIRC">if ($(test &) iswm test this)</source>
  
If you need to use any of these special characters as plain text in an expression where they are taken as special (not always for &), you can try to use a regular expression instead.
+
If you need to use any of these special characters as plain text in an expression where they are taken as wildcard character (that is, not always the case for &), you can try to use a {{mIRC|regex|regular expression}} instead.
 +
 
 +
The number of function/feature of the language supporting wildcard matching is simply too high to make a list, but here are the main usage:
 +
 
 +
* The iswm operator can be used with /if (and the like) to make a wildcard comparison:
 +
<source lang="mIRC">
 +
if (test* iswm $1-) { }
 +
 
 +
While there is a "?" wildcard for 1 character, and a "*" wildcard for zero-or-more characters, there isn't a wildcard for one-or-more characters. However you can obtain the same result by combining the ? and * together. For example, if you have a string where you want to remove leading zeroes, you can do something like:
 +
 
 +
//var %a 00000123 | while (0* iswm %a) var %a $mid(%a,2) | echo -a result: %a
 +
 
 +
and this will always ensure the string cannot begin with '0'. However, if the input is actually an integer and you do not want to reduce a string of all zeroes to the empty string, you can search for zero followed by 1 wildcard character followed by 0-or-more characters. This causes it to avoid removing a zero when that would be removing the only remaining character.
 +
 
 +
//var %a 0000000 | while (0?* iswm %a) var %a $mid(%a,2) | echo -a result: %a
 +
 
 +
The iswm operator matches on a case-insensitive basis, but only as far as treating the a-z and A-Z ranges the same, so $upper($chr(233)) and $lower($chr(233)) will be seen as different. If you need to see 'Test' and 'test' as different, then use the iswmcs for a case-sensitive comparison where 'z' and 'Z' are no longer seen as the same.
 +
 
 +
</source>
 +
Wildcard-matches can also be used in {{mIRC|$wildtok|token manipulation}}, {{mIRC|$hfind|hash tables}}, {{mIRC|$fline|custom windows}}, {{mIRC|on events|ON events}}, {{mIRC|$var|variables}}, etc. etc.
 +
[[Category:mIRC|wildcards]]

Latest revision as of 14:38, 6 October 2024

Wildcard characters are special characters that are interpreted when comparing text.

There are three meaningful wildcard characters:

  •  ? - matches a single character
  • * - matches everything (including nothing)
  • & - matches a whole word if used alone

For example the expression "t*s a *?t" matches the string "this is a text"

If & is not used alone it matches the plain text '&' character

Note: It also doesn't match $chr(32) if used to match a whole word, see below

"test &" matches "test this" or "test that"

"test &his" matches only "test &his"

"test thi&" matches only "test thi&"

"test th&s" matches only "test th&s"

"test &" doesn't match "test $chr(32)" (consider $chr(32) to be evaluated here)

Be careful when using the & wildcard character inside /if (and the like: $iif, /while, /elseif) it could be interpreted as the & bitwise operator:

if (test & iswm test this)

is not true because & is used as the bitwise operator, you can use $eval() to force mIRC to read the parameter the way you want:

if ($(test &) iswm test this)

If you need to use any of these special characters as plain text in an expression where they are taken as wildcard character (that is, not always the case for &), you can try to use a regular expression instead.

The number of function/feature of the language supporting wildcard matching is simply too high to make a list, but here are the main usage:

  • The iswm operator can be used with /if (and the like) to make a wildcard comparison:
if (test* iswm $1-) { }
 
While there is a "?" wildcard for 1 character, and a "*" wildcard for zero-or-more characters, there isn't a wildcard for one-or-more characters. However you can obtain the same result by combining the ? and * together. For example, if you have a string where you want to remove leading zeroes, you can do something like:
 
//var %a 00000123 | while (0* iswm %a) var %a $mid(%a,2) | echo -a result: %a
 
and this will always ensure the string cannot begin with '0'. However, if the input is actually an integer and you do not want to reduce a string of all zeroes to the empty string, you can search for zero followed by 1 wildcard character followed by 0-or-more characters. This causes it to avoid removing a zero when that would be removing the only remaining character.
 
//var %a 0000000 | while (0?* iswm %a) var %a $mid(%a,2) | echo -a result: %a
 
The iswm operator matches on a case-insensitive basis, but only as far as treating the a-z and A-Z ranges the same, so $upper($chr(233)) and $lower($chr(233)) will be seen as different. If you need to see 'Test' and 'test' as different, then use the iswmcs for a case-sensitive comparison where 'z' and 'Z' are no longer seen as the same.

Wildcard-matches can also be used in token manipulation, hash tables, custom windows, ON events, variables, etc. etc.