match(needle, haystack, ...) -- search for needle in haystack
matchi(needle, haystack, ...) -- search for needle in haystack (case insensitive)
For these you can use simplified regex-style wildcards:
- * = match 0 or more characters
- *? = match 0 or more characters, lazy
- + = match 1 or more characters
- +? = match 1 or more characters, lazy
- ? = match one character
Examples:
match("*blah*", "this string has the word blah in it") == 1
match("*blah", "this string ends with the word blah") == 1
You can also use format specifiers to match certain types of data, and optionally put that into a variable:
- %s means 1 or more chars
- %0s means 0 or more chars
- %5s means exactly 5 chars
- %5-s means 5 or more chars
- %-10s means 1-10 chars
- %3-5s means 3-5 chars.
- %0-5s means 0-5 chars.
- %x, %d, %u, and %f are available for use similarly
- %c can be used, but can't take any length modifiers
- Use uppercase (%S, %D, etc) for lazy matching
The variables can be specified as additional parameters to match(), or directly within {} inside the format tag (in this case the variable will always be a global variable):
match("*%4d*","some four digit value is 8000, I say",blah)==1 && blah == 8000
match("*%4{blah}d*","some four digit value is 8000, I say")==1 && blah == 8000