Regular Expressions 101

Community Patterns

Simple, universal and short regex to find quoted strings. Invalid quotes inside string ignored. flag s (single-line) allows to find multiline strings

1

Regular Expression
Python

r"
([\'\"\`])(.*)\1
"
gm

Description

  • 'string in simple quotes'
  • "in double-quotes"
  • in back-quotes
  • "Works good with symbols ' or " or ` inside the string"
  • "All another type quotes "' inside string are ignored" use something like \ or " or '
  • " Matches only identical quotes on string start and end ' // regex can`t find this
  • group 1 saves quote symbol
  • group 2 saves clear text

Valid strings

  • "Something something something something"
  • 'Something something something something'
  • Something something something something
  • "Something something ' ` something something"
  • 'Something something " ` something something'
  • Something something " ' something something
  • "Something something " something something"
  • 'Something something ' something something'
  • Something something \ something something`
  • Something something \\ something something
Submitted by V. Martian - 4 years ago