function::matched - Linux
Overview
The function::matched
command checks if an input string matches a specified regular expression pattern.
Syntax
function::matched PATTERN STRING [FLAGS]
Parameters
| Parameter | Description |
|:—|:—|
| PATTERN | The regular expression pattern to check against. |
| STRING | The input string to match. |
| FLAGS | Optional flags to modify the search behavior. |
Flags
| Flag | Description |
|:—|:—|
| -i
| Case-insensitive matching. |
| -s
| Single-line matching. |
| -m
| Multi-line matching. |
| -x
| Exact match. |
Examples
Simple matching:
function::matched "foo" "foobar" # Returns True
Case-insensitive matching:
function::matched -i "FOO" "foobar" # Returns True
Multi-line matching:
function::matched -m "foo\nbar" "foobar\nhello" # Returns True
Common Issues
- Invalid regular expression: Ensure that the pattern is a valid regular expression. Check for syntax errors and proper escaping.
- No match found: Verify that the input string actually contains the pattern you’re searching for.
Integration
function::matched
can be used in scripts and pipelines to conditionally run commands or process data based on matching criteria:
if function::matched "error" "$log"; then
echo "An error occurred!"
fi