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.

2 447

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"]

Comments

You have to be logged in to add a comment

User Comments

Insert Math Markup

ESC
About Inserting Math Content
Display Style:

Embed News Content

ESC
About Embedding News Content

Embed Youtube Video

ESC
Embedding Youtube Videos

Embed TikTok Video

ESC
Embedding TikTok Videos

Embed X Post

ESC
Embedding X Posts

Embed Instagram Post

ESC
Embedding Instagram Posts

Insert Details Element

ESC

Example Output:

Summary Title
You will be able to insert content here after confirming the title of the <details> element.

Insert Table

ESC
Customization
Align:
Preview:

Insert Horizontal Rule

#000000

Preview:


View Content At Different Sizes

ESC

Edit Style of Block Nodes

ESC

Edit the background color, default text color, margin, padding, and border of block nodes. Editable block nodes include paragraphs, headers, and lists.

#ffffff
#000000

Edit Selected Cells

Change the background color, vertical align, and borders of the cells in the current selection.

#ffffff
Vertical Align:
Border
#000000
Border Style:

Edit Table

ESC
Customization:
Align:

Upload Lexical State

ESC

Upload a .lexical file. If the file type matches the type of the current editor, then a preview will be shown below the file input.

Upload 3D Object

ESC

Upload Jupyter Notebook

ESC

Upload a Jupyter notebook and embed the resulting HTML in the text editor.

Insert Custom HTML

ESC

Edit Image Background Color

ESC
#ffffff

Insert Columns Layout

ESC
Column Type:

Select Code Language

ESC
Select Coding Language

Insert Chart

ESC

Use the search box below

Upload Previous Version of Article State

ESC