STRMATCH

Purpose:

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

Syntax:

STRMATCH(

"pattern", "srchstr", "delimit", caseflag, exactflag, substrflag)

"pattern"

-

A string. The pattern string to search for.

"srchstr"

-

A string. The search string to search in.

"delimit"

-

Optional. A string specifying the characters used to separate srchstr into individual substrings. Defaults to no character.

caseflag

-

Optional. An integer, the case sensitivity flag.

0:

case not significant (default).

1:

case significant

exactflag

-

Optional. An integer, the substring must match the number of characters in the pattern exactly. Only valid if a delimiter string is specified.

0:

the exact number of characters is not required (default).

1:

the substring must match the exact number of characters in pattern.

substrflag

-

Optional. An integer, return the substring index instead of the character index. Only valid if a delimiter string is specified.

0:

return the character index (default).

1:

return the substring index.

Returns:

A series, the indices of srchstr that contain pattern.

Example:

strmatch("abb", "abbababba")

 

returns {1, 6} indicating the pattern "abb" is located at index 1 and 6 of "abbababba".

Example:

strmatch("AAA", "baaAAAab")

 

returns {2, 3, 4, 5} since the case insensitive pattern "AAA" is located at indices 2 through 5 of "baaAAAab".

Example:

strmatch("AAA", "baaAAAab", 1)

 

returns {4} since the case sensitive pattern "AAA" is located only at index 4.

Example:

strmatch("xxx", "baaAAAab")

 

returns {}, an empty series since "xxx" is not located in the search string.

Example:

strmatch("xXx", "bxxx;xXxx;xXx;xxx;xx", ";", 0, 0)

 

returns {6, 11, 15}, since "xXx" is located at indices 6, 11 and 15 where each substring is separated by the ";" character. A match occurs only if the first three characters of a substring matches "xXx" independent of case. Only one match per substring is returned.

Example:

strmatch("xXx", "bxxx;xXxx;xXx;xxx;xx", ";", 1, 0)

 

returns {6, 11}, since "xXx" is located at indices 6 and 11 where each substring is separated by the ";" character. A match occurs only if the first three characters of a substring matches "xXx" with the same case. Only one match per substring is returned.

Example:

strmatch("xXx", "bxxx;xXxx;xXx;xxx;xx", ";", 0, 1)

 

returns {11, 15}, since "xXx" is located at indices 11 and 15 where each substring is separated by the ";" character. A match occurs only if the substring contains exactly three characters and matches "xXx" independent of case. Only one match per substring is returned.

Example:

strmatch("xXx", "bxxx;xXxx;xXx;xxx;xx", ";", 1, 1)

 

returns {11}, since "xXx" is located at index 11 where each substring is separated by the ";" character. A match occurs only if the substring contains exactly three characters and matches "xXx" with the same case. Only one match per substring is returned.

Example:

strmatch("xXx", "bxxx;xXxx;xXx;xxx;xx", ";", 0, 1, 1)

 

returns {3, 4}, since "xXx" is found in the third and fourth substrings where each substring is separated by the ";" character. A match is case insensitive. Only one match per substring is returned.

Example:

strmatch("xXx", "bxxx;xXxx;xXx;xxx;xx", ";", 1, 1, 1)

 

returns {3}, since "xXx" is found in the third substring where each substring is separated by the ";" character. A match is case sensitive. Only one match per substring is returned.

Remarks:

If no match is found, an empty series is returned.

 

The "delimit" string can contain more than one delimiter characters to mark a substring within the search string.

 

Use STRGET to return the nth substring. For example:

 

teststr = "bxxx;xXxx;xXx;xxx;xx";

subnum = strmatch("xXx", teststr, ";", 1, 1, 1);

substr = strget(subnum[1], teststr, ";")

 

subnum == {3}

substr == "xXx"

See Also:

STRCAT

STRCMP

STREXTRACT

STRFIND

STRGET

STRREPLACE

STRSORT