STRMATCH(3ast) STRMATCH(3ast)

# [NAME](#NAME)

strmatch - match shell file patterns

# [SYNOPSIS](#SYNOPSIS)

int strmatch(const char* s, const char* p)  
char* submatch(const char* s, const char* p, int flags)

# [DESCRIPTION](#DESCRIPTION)

*strmatch* compares the string *s* with the shell pattern *p* and returns 1 for match and 0 otherwise. *submatch* does a leading substring match of the shell pattern *p* with the string *s*. If *flags* is 0 then the match is minimal, otherwise a maximal match is done. A pointer to the first character after the matched substring is returned, *0* if there is no match.

Except for *&* and *!*, each shell pattern has an equivalent [*egrep*(1)](/man/os/ksh/egrep.1) construct.

```
	sh pattern	egrep RE	description
	*		.*		0 or more chars
	?		.		any single char
	[.]		[.]		char class
	[!.]		[^.]		negated char class
	*(.)		(.)*		0 or more of
	+(.)		(.)+		1 or more of
	?(.)		(.)?		0 or 1 of
	(.)		(.)		1 of
	@(.)		(.)		1 of
	a|b		a|b		a or b
	a&b				a and b
	!(.)				none of
```

\\ is used to escape \*, ?, (, |, &, ), \[, and \\ outside of \[...].

# [SEE ALSO](#SEE_ALSO)

[grep(1)](/man/os/ksh/grep.1)

# [BUGS](#BUGS)

An unbalanced ) terminates the top level pattern.  
Nested & and ! constructs are non-intuitive and are computationally intensive.

---

Document: strmatch(3ast) from ksh 1.0.10-r37 (Chainguard OS)
Source: https://github.com/ksh93/ksh
