ThakeeNathees / pocketlang

A lightweight, fast embeddable scripting language.
https://thakeenathees.github.io/pocketlang/
MIT License
1.52k stars 80 forks source link

[Module] Add re module for easy regular expressions operations #266

Open khchen opened 2 years ago

khchen commented 2 years ago

This re module is based on a modified pike vm and have following features:

  1. Lightweight (about 15~20k only, depend on compile flags).
  2. Support almost all common RE pattern and group capture (except backreferences).
  3. Guarantees that any input regex will scale O(n) with the size of the string.
  4. Support global mode and case insensitive mode.
  5. Support UTF8.

Example:

print(re.match('\\d', 'a1b2c3d4'))
print(re.match('\\d', 'a1b2c3d4', re.G))
print(re.test('[😀-😆]', '😁'))
print(re.test('[😀-😆]', '👻'))
print(re.split('\\d', 'a1b2c3d'))

Output:

["1"]
["1", "2", "3", "4"]
true
false
["a", "b", "c", "d"]