Forrest logo
back to the expr tool

expr:tldr:b34dc

expr: Match a specific substring against an anchored pattern.
$ expr match "${string}" '${pattern}'
try on your machine

The command "expr match ${string} '${pattern}'" is used to perform pattern matching on a given string using the specified pattern.

Here's an explanation of the command and its components:

  1. "${string}": This is a variable that holds the string value on which pattern matching is performed.

  2. '${pattern}': This is a variable that holds the pattern to match against the string. The pattern can be specified using regular expressions or simple strings.

  3. "expr match": This is the command itself, which is used to perform a pattern matching operation.

The output of this command will be the length of the matched substring if a match is found, or 0 if no match is found. It determines the number of characters at the beginning of the string that match the specified pattern.

Note: The use of single quotes around '${pattern}' is necessary to prevent the shell from expanding any special characters or variables within the pattern.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the expr tool