Building regex engine for fun and learn.
Referrence: Regular Expression Matching Can Be Simple And Fast got from build-your-own-x
Clone the repo
git clone https://github.com/kshku/regex-exp.git
cd regex-expBuild using CMake
cmake -S . -B build
cmake --build buildcmake --build build --target docsand then you can open the build/docs/output/html/index.html in browser.
The executable is built in build directory and named regexer. To run, execute
build/regexer "text" "regex-pattern"Literal characters
Dot(.) -> Matches any single character
Kleene star(*) -> Zero or more repetition of previous character
Plus(+) -> One or more repetition of previous character
Optional(?) -> Zero or one repetition of previous character
Anchors(^, $) -> Matches beginning(^) or end($) of the line
Character classes([]) -> Matches any of the character or character range specified
Backslash(\) -> Escape character
Alternation(|) -> Matches either the expression on left or expression on right
Grouping(()) -> Groups multiple expressions together to apply operators to the entire group
The run_readme_examples.sh script reads this readme and tries to run all the lines that start with build/regexer.
It can be used to to run all these following examples.
Just run
./run_readme_examples.shto run all these examples
build/regexer "somebody saw nobody" "saw"
build/regexer "somebody saw nobody" "sa?w"
build/regexer "somebody sw nobody" "sa*w"
build/regexer "somebody saaw nobody" "sa+w"
build/regexer "somebody sa+w nobody" "sa\+w"
build/regexer "somebody saw nobody" "^some"
build/regexer "somebody saw nobody" "^saw"
build/regexer "somebody saw nobody" "y$"
build/regexer "somebody saw nobody" "^some.*y$"
build/regexer "somebody saeiouw nobody" "s[aeiou]*w"
build/regexer "somebody saeiouw nobody" "s[aeiou]w"
build/regexer "somebody saeiouw nobody" "s[aeiou]+w"
build/regexer "somebody saw nobody" "s[^A-Z]w"
build/regexer "somebody saw nobody" "s[^A-Za]w"
build/regexer "somebody saw nobody" "s[^A-Z]w"
build/regexer "somebody saw nobody" "s[^a-z]w"
build/regexer "somebody saw nobody" "s[^a-A]w"
build/regexer "somebody saw nobody" "s[^a\-A]w"
build/regexer "somebody saw nobody" "s[^\-A]w"
build/regexer "somebody sa]w nobody" "s[]a]+w"
build/regexer "somebody sa]-w nobody" "s[]a-]+w"
build/regexer "somebody sa]-w nobody" "s[-\]a]+w"
build/regexer "somebody saw nobody" "nobody|somebody"
build/regexer "somebody saw nobody" "^somebody|^nobody$"
build/regexer "somebody saw nobody" "^somebody$|nobody$"
build/regexer "somebody saw nobody" "^somebody$|^nobody$"
build/regexer "somebody saw nobody" "somebody$|^nobody$"
build/regexer "somebody saw nobody" "somebody|^nobody$"
build/regexer "somebody saw nobody" "somebody|^nobody"
build/regexer "somebody saw nobody" "^somebody|^nobody"
build/regexer "somebody saw nobody" "somebody$|^nobody"
build/regexer "somebody saw nobody" "somebody$|^nobody|saw"
build/regexer "somebody saw nobody" "s(a|b)w"
build/regexer "somebody sabw nobody" "s(a|b)w"
build/regexer "somebody sabw nobody" "s(a|b)+w"
build/regexer "somebody scw nobody" "s(a|b)+w"
build/regexer "somebody scw nobody" "s(a|b|c)+w"
build/regexer "somebody scw nobody" "s(a|b|c)w"
build/regexer "somebody saw nobody" "s()w"
build/regexer "somebody saw nobody" "s(b|c)w"
build/regexer "somebody sabbbaaaaabw nobody" "s(a*b)+w"
build/regexer "somebody sabbbaaaaabw nobody" "s((a)*b)+w"
build/regexer "somebody sacbbbacacacacacbw nobody" "s((ac)*b)+w"