This is a basic regular expression engine. It currently supports only a handful of features.
const float = new Regex('[0-9]*\\.[0-9]+');
float.match('3.50'); // true
float.match('42'); // false
You can also use a RegExp
literal as the source pattern.
This is primarily useful for syntax highlighting and escapes.
However, when doing this, errors in the pattern will be thrown by RegExp
rather than Regex
.
new Regex(/[0-9]*\.[0-9]+/);
Supported features are:
- Basic character matching
- Dot e.g.
.+
- Repetition e.g.
a?b*c+
- Grouping e.g.
(abc)
- Character classes e.g.
[abc]
- Character ranges e.g.
[a-z]
All other regex features are not supported.
The most notable omission is backtracking. For example, new Regex('a+a').match('aa')
yields a false-negative.