Learning Regex

I am trying to learn more about the basics of regex because creating a good markdown parser kind of requires it. Here are some notes on the subject.

Learning Regex

Why Try to Learn Regex Better

How I am Attempting to Learn Regex Better

Notes

  const a = /html/ // Regex searches for exact matches on html
  const a = /.*/ // Regex  matches every instance of all characters
  const a = /<\/?html>/ // Regex matches opening and closing <html> tags

= |: Means "OR" -> match the pattern before the pipe or after the pipe, where | = "pipe"

  const a = /<(h1|h2)>/ // Regex matches opening h1 or h2 tags
  const a = /<(?:h1|p)>(?<innerText>.*?)<\/(?:h1|p)>/ // Regex matches everything inside <h1> and <p> tags
  const a = /[\d\w]/ // Matches on any letter or digit
  const b = /[\d\w]+/ // Matches on any number of characters or digits
  const c = /[0-5]+/ // Matches on any number of instances of digits from 0 to 5
  const d = /[a-eX-Z]+/ // Matches on any number of instances of characters a-e or X, Y, and Z 
  const e = />[^<]+</ // Matches on everything between the right arrow and the left arrow
  const f = /(\A.*?)<a/ // matches all HTML up the first anchor tag
  const a = /(\w{3}-).*?\1/ // Look for three letters followed by a hyphen followed by three letters followed by a hyphen with any characters in between the two matches of the pattern - this first match will be the only match of the entire pattern.
  const a = /(\w+)\s+(\w+)\s+(\w+)/ // Get the first three words
  /* $3 $2 $1 -> rearrange the first three words using capture groups */
  const a = /\w(?=\s)/ // Look for characters that are immediately followed by a space
  const a = />(?!\s)/ // Look for a ">" character that is not immediately followed by a space
  const a = /^(?!.*(?:html|body)).*?$/ // Matches all lines that do not contain the word HTML or body

Email Example

const a = /^.*?@.*?\.\w+/ // (starts with and contains any characters)@(any letters).any characters
var pattern = new RegExp(/\w+/,"gi");
var user = "Tim";
var pattern2  new RegExp("name: ".concat(user),"gi");
import re
pattern = re.compile('[a-z]+')
pattern.findall("This is my test sentence") # -> ["his", "is", "my", "test", "sentence"]
pattern = re.compile('[a-zA-Z]+')
pattern.findall("This is my test sentence") # -> ["This", "is", "my", "test", "sentence"]