Loading…

Glob And Regex Lite Matcher

Neither MQL4 nor MQL5 has pattern matching beyond StringFind for an exact substring. Anything shaped like "does this symbol name match EURUSD*,*JPY" or "does this comment look like a magic tag" ends up as a pile of StringSubstr calls that gets rewritten every time the pattern changes. This header covers the two shapes that actually come up in trading code. WildcardMatch handles '*' and '?' glob patterns, anchored to the whole string the way a file mask is. MatchesAnyWildcard wraps it for the common case of a comma-separated filter list in an input string - "EURUSD*,*JPY,GBP??" - which is what a symbol whitelist or blacklist input actually looks like in practice. RegexMatch is a real backtracking engine, not a wrapper around wildcards. It supports literal characters, '.', the '*' '+' '?' quantifiers, '^' and '$' anchors, '[...]' character classes with ranges and negation, and the \d \w \s shorthands (and their negations \D \W \S). What it deliberately does not support is groups, capturing, alternation or backreferences - a log-line filter or a comment-tag check does not need PCRE, and every feature left out is a feature that cannot silently misbehave on a pattern a user did not expect to be that powerful. Anchoring is search-based like grep without -x: '^' and '$' pin an end when present, otherwise the pattern may match starting anywhere in the text. Both matchers come with a NoCase variant that folds ASCII case before matching. There is no locale-aware folding - documented as a limitation, not hidden. The header is self-contained. No dependencies, no DLLs, plain functions callable from a script, an indicator or an expert. Notes and limitations - No groups, capture or alternation. This is a filter engine, not a text processing library - if a pattern needs "(a|b)", it is out of scope by design. - No repetition counts like {2,4}. Use '*' '+' '?' or write the class out explicitly. - Case folding is ASCII only. \w \d \s already treat both cases of a letter identically, so RegexMatchNoCase mainly matters for plain literals. - The regex engine is a plain recursive backtracker with no memoisation. Pathological patterns (heavily nested quantifiers over long text) can be slow, exactly as with any backtracking engine - keep patterns short, which is the realistic case for symbol filters and comment tags anyway. - A '[' that is never closed is treated as a literal '[', not an error, so a typo degrades gracefully instead of throwing.

Script · MT5 · v1.0 · Free

About Glob And Regex Lite Matcher

Glob And Regex Lite Matcher is a script for MetaTrader 5. It shows several symbols in one panel. It has 1 setting, such as Symbol filter list. MQL source code included.

Files in the download: PatternMatcher.mq5.mqh, PatternMatcher.txt, PatternMatcherDemo.ex5, PatternMatcherDemo.mq5.

Settings

SettingDefaultWhat it does
Symbol filter listEURUSD*,*JPY,GBP??DComma list used in the filter demo

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: EURUSD · Dashboards & Scanners · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria