MQLArticles/Utils/StrMatch/README.md
38 righe
1,4 KiB
Markdown
Niquel Mendoza
2026-03-27 17:06:17 +00:00
# StrMatch
Nique_372
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
Niquel Mendoza
2026-03-27 17:06:17 +00:00
```cpp
CSimpleStringMatch::SimpleMatchInString("hello.png", "*.png"); // true
```
Nique_372
2026-04-30 15:56:25 -05:00
## Supported Patterns
Niquel Mendoza
2026-03-27 17:06:17 +00:00
Nique_372
2026-04-30 15:56:25 -05:00
| Character | Meaning | Example |
Niquel Mendoza
2026-03-27 17:06:17 +00:00
|---|---|---|
Nique_372
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.
Niquel Mendoza
2026-03-27 17:06:17 +00:00
Nique_372
2026-04-30 15:56:25 -05:00
## Examples
Niquel Mendoza
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
```
Nique_372
2026-04-30 15:56:25 -05:00
## Notes
Niquel Mendoza
2026-03-27 17:06:17 +00:00
Nique_372
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.