Weyland provides an alternative way to write regular expression handling incomplete matching and lexers using them.
pip install weyland
A. Syntax of regular expression
Weyland offers three classes: Regex for regexes, Match for matches and Element.
A Regex is composed of Elements.
Below is a short definition of the language used to define Regex.
ab a then b
A class is a group of characters represented by a single special character.
\dany digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
\wany digits, letters and the underscore character (_)
.any characters which is not a new line
A position can be also represented by a single special character.
^start of the string (can be used only at the start of the Regex)
$end of the string (can be used only at the end of the Regex)
[ab] a or b
A.5 Optionality and repetition
Optionality and repetition of a character, a class or a choice can be represented by a single special character.
a?bb or ab (a is optionnal, it can appear between 0 and 1 time),
a+bab, aab, aaab, aaaab, etc. (a is mandatory, it must appear betweean 1 and X times),
a*bb, ab, aab, aaab, aaaab, etc. (a is optionnal, it can appear between 0 and X times).
Optionality and repetition can't be used for positions.
A.6 Escaping special characters
In order to use a special characters as a normal character in a regex, you must escape them by putting the () character before it.
There are 12 escapable characters: #, @, &, ., ^, $, [, ], ?, +, *, .
- In a choice, you can only choose between one element not between sequences,
- In a choice, no repeated element nor optionnal element.
- In a choice, no start nor end of the string elements.
- You can only use terminals and special characters in regex definitions.
- You can't define groups in regex definitions.
Weyland provides also several lexers using the incomplete matching feature of Weyland's regex.
B.1 Languages available
A set of lexers and associated tokens are available for the following languages:
- Data language: json,
- Programming languages: ash, lua, python,
- Description languages: bnf, hamill.
List of websites about Weyland: