Returns the portion of a search string that contains a pattern string.
STRFIND("pattern", "srchstr", caseflag, wildcards)
(str, idx) = STRFIND("pattern", "srchstr", caseflag, wildcards)
"pattern" |
- |
A string. The pattern string to search for. |
||||||
"srchstr" |
- |
A string. The search string to search in. |
||||||
caseflag |
- |
Optional. An integer, the case sensitivity flag.
|
||||||
wildcards |
- |
Optional. An integer, process * (any sequence) and ? (single character) as wildcard characters or use regular expressions (regex).
|
A string.
(str, idx) = STRFIND("pattern", "srchstr", caseflag, wildcards) returns the matching string and starting string index in two separate variables.
strfind("XINC", "YOR:12.3 XINC:1.0 YREF:120.0")
returns the string: XINC:1.0 YREF:120.0.
W1: RUN1.1.ANALOG1
s = strfind("an", getwformula(W1))
s == "ANALOG1".
W1: RUN1.1.ANALOG1
s = strfind("an", getwformula(W1), 1)
returns an empty string since the search is case sensitive.
s = strfind("xX*", "bxxx;Xxx;xXx;xxx;xx", 1, 0)
returns an empty string since the search string does not contain the * character.
(s, idx) = strfind("日", "abc日本語def");
s == "日本語def"
idx == 4
s = strfind("xX*", "bxxx;Xxx;xXx;xxx;xx", 1, 1)
s == "xXx;xxx;xx"
The case sensitive wildcard pattern "xX*" indicates the letters xX followed by any other characters.
s = strfind("[A-Z]+", "abcDEF123", 1, 2);
s == "DEF"
The regular expression [A-Z]+ matches upper case letters.
If the search string does not contain the pattern, an empty string is returned.
When wildcard is set to 1, use * in "patstr" to match any character sequence and ? to match a single character. To search for a literal * or ? character instead of treating them as wildcards, escape them by prefixing a backslash: \* or \?.
When wildcard is set to 2, the search pattern "patstr" is interpreted a regular expression. Regular expressions (regex) provide far more flexibility than simple wildcards. A regular expression can indicate character classes (match a character from a set), quantifiers (how many times a pattern repeats), anchors (position in the string) and logical operators. For example, the pattern:
[0-9]{4}
matches 4 digits.
strfind("[0-9]{4}", "abc987x1234y", 1, 2)
returns "1234" since this is the first pattern that contains 4 digits.
Below is a summary of regular expression patterns when wildcards is 2:
Category |
Character |
Description / Matches |
|---|---|---|
Character Matches |
|
Any single character except a newline (\n). |
Character Matches |
|
Any digit character (equivalent
to |
Character Matches |
|
Any alphanumeric "word" character (letters, numbers, underscore). |
Character Matches |
|
Any whitespace character (spaces, tabs, line breaks). |
Character Classes |
|
Any single character inside the brackets (a, b, or c). |
Character Classes |
|
Any single character NOT inside the brackets. |
Quantifiers |
|
0 or more repetitions of the preceding token. |
Quantifiers |
|
1 or more repetitions of the preceding token. |
Quantifiers |
|
0 or 1 repetition (makes the preceding token optional). |
Quantifiers |
|
Between |
Anchors |
|
The start of the string or line. |
Anchors |
|
The end of the string or line. |
Anchors |
|
A word boundary (the edge position between a \w and a non-\w character). |
Logic / Groups |
|
Alternation operator (acts like a logical OR statement). |
Logic / Groups |
|
Capturing group. Isolates tokens and remembers the match context. |
Digits only: ^[0-9]+$
Uppercase letters: ^[A-Z]+$
Alphanumeric: ^[A-Za-z0-9]+$
Floating‑point number: ^[+-]?\d+(\.\d+)?$
Email (simple): ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$
See STRMATCH to return the indices of matching patterns in a delimited search string.