STRFIND

Purpose:

Returns the portion of a search string that contains a pattern string.

Syntax:

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.

0:

case not significant (default)

1:

case significant

wildcards

-

Optional. An integer, process * (any sequence) and ? (single character) as wildcard characters or use regular expressions (regex).

0:

no wildcards and no regular expressions (default)

1:

support * and ? wildcards

2:

support regular expressions (regex)

Returns:

A string.

 

(str, idx) = STRFIND("pattern", "srchstr", caseflag, wildcards) returns the matching string and starting string index in two separate variables.

Example:

strfind("XINC", "YOR:12.3 XINC:1.0 YREF:120.0")

 

returns the string: XINC:1.0 YREF:120.0.

Example:

W1: RUN1.1.ANALOG1

 

s = strfind("an", getwformula(W1))

 

s == "ANALOG1".

Example:

W1: RUN1.1.ANALOG1

 

s = strfind("an", getwformula(W1), 1)

 

returns an empty string since the search is case sensitive.

Example:

s = strfind("xX*", "bxxx;Xxx;xXx;xxx;xx", 1, 0)

 

returns an empty string since the search string does not contain the * character.

Example:

(s, idx) = strfind("日", "abc日本語def");

 

s == "日本語def"

idx == 4

Example:

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.

Example:

s = strfind("[A-Z]+", "abcDEF123", 1, 2);

 

s == "DEF"

 

The regular expression [A-Z]+ matches upper case letters.

Remarks:

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:

 

Regex Quick Summary

 

Category

Character

Description / Matches

Character Matches

.

Any single character except a newline (\n).

Character Matches

\d

Any digit character (equivalent to [0-9]).

Character Matches

\w

Any alphanumeric "word" character (letters, numbers, underscore).

Character Matches

\s

Any whitespace character (spaces, tabs, line breaks).

Character Classes

[abc]

Any single character inside the brackets (a, b, or c).

Character Classes

[^abc]

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

{n,m}

Between n and m repetitions of the token.

Anchors

^

The start of the string or line.

Anchors

$

The end of the string or line.

Anchors

\b

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.

 

Common Regex Patterns

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.

See Also:

STRCAT

STRCMP

STREXTRACT

STRGET

STRIDXGET

STRMATCH

STRREPLACE

STRSORT

STRTRIM