Regex
Last updated on
Regex (regular expressions) is such an amazing technology. It’s the most popular (and certainly powerful) text search engine.
Links
- As a learning resource, RegexOne guides you with excercises and is a great pratise tool.
- regex tutorials has a tutorial and nice excercises too.
- regexr.com is my goto website for testing expressions. Regex101 is a close second website if you prefer something different.
- Visually, this Dev.to guide is brief and to the point.
- If you want an more advanced documentation, regular-exresions.info may help advanced users.
- Are you a visual person? try this regex diagram generator. It’s very powerful!
How to
- Match all the caracters between 2 strings
# expression
(?<=This is)(.*)(?=sentence)
# this matches
This is "just a simple" sentence
The pattern looked closely:
(?<=\s|^) #to look behind the match
(stackoverflow) #the string you want. () optional
(?=\s|$) #to look ahead.
source: StackOverflow
- You can even use regex in CSS
Apps
- For CLI, ripgrep is king. It also has ripgrep-all (unrelated to rg) that search among pdf, docx, sqlite, jpg, movie subtitles and more.
- you have the guide here
- Do you want a GUI? here. You are welcome.
- If you want to go the other way, you can provide the cases, and
grex
will infer the regex expression