Notebook of Bloody Regex
Aug-2022
Tested in search method of vim editor.
Get single letter [a-z]
Number [0-9]
Get multiple letters, (first letter and the following letters)
\w
[a-z]*
Get multiple letters rather they are lower or uppercase
[a-zA-Z]*
Get single character, use the character itself or
\W
matches any non-word character
Practices
Get all text inside ""
like a string value in PL
"[^"]"
Get everything inside brackets with the brackets together
{[^}]}
means, start with {
get all until }₁
and get the last }₂
Get all newline characters after any last-character, if the line ends with (.) or a letter, or a bracket.
[^\n]\n
Replace all multiple emply lines, like every two or three unnecessary empty line into one in the entire document.
- Get every EOL ending with any type of char
–:%s/[^\n]\n/
- Add an irrevelant character as a marker by replacing with
–:%s/[^\n]\n/ÜÜÜ/g
- Get marker characters and replace them with newline
–:%s/ÜÜÜ/\r\g
Get all html tags with opening and enclosing together
Example: <code>some code text</code>
:%s/<\W*code>