MQLArticles/Utils/StrMatch/README.md

38 lines
1.4 KiB
Markdown
Raw Permalink Normal View History

2026-03-27 17:06:17 +00:00
# StrMatch
2026-04-30 15:56:25 -05:00
A module with a single pattern matching function for strings. Allows comparing a string against a pattern with special characters.
## Usage
2026-03-27 17:06:17 +00:00
```cpp
CSimpleStringMatch::SimpleMatchInString("hello.png", "*.png"); // true
```
2026-04-30 15:56:25 -05:00
## Supported Patterns
2026-03-27 17:06:17 +00:00
2026-04-30 15:56:25 -05:00
| Character | Meaning | Example |
2026-03-27 17:06:17 +00:00
|---|---|---|
2026-04-30 15:56:25 -05:00
| `*` | Any sequence of characters, searches up to the farthest occurrence after the `*` | `*.png` = any .png file |
| `?` | Exactly one character of any kind | `?.txt` = a.txt, b.txt |
| `^` | Exactly one digit (0-9) | `file^.csv` = file1.csv |
| `~` | Any sequence of characters, searches up to the nearest occurrence after the `~` | `~\\` = Only folder of 1 level |
Patterns can be combined freely.
2026-03-27 17:06:17 +00:00
2026-04-30 15:56:25 -05:00
## Examples
2026-03-27 17:06:17 +00:00
```cpp
SimpleMatchInString("hello_word.png", "*.png"); // true
SimpleMatchInString("hello_word.png", ".png*"); // false
SimpleMatchInString("aksdgello", "????gello"); // true
SimpleMatchInString("123a", "*^^^a"); // false
SimpleMatchInString("file123.txt", "file^^^.txt"); // true
SimpleMatchInString("anything", "*"); // true
SimpleMatchInString("", "*"); // true
SimpleMatchInString("abc", "??"); // false
```
2026-04-30 15:56:25 -05:00
## Notes
2026-03-27 17:06:17 +00:00
2026-04-30 15:56:25 -05:00
- `~~` is not supported as a valid pattern. The character after `~` acts as a sequence terminator.
- The pattern `~` or `*` only equals "anything" when it stands alone.