Obromios
Obromios

Reputation: 16373

Regex that can find lines continued with a comma

I wish use a regex to be used in Sublime Text 3to find commands like

get :action, id: 1, name: 'John',
   children: 3

My initial attempt is get :[\w]*,[^\n]*. This will work if the command is on a single line i.e

get :action, id: 5, name: 'Chris'

but does not work when the command is written over several lines with a comma continuation. What is the regex that will work with a multi-line command?

The Sublime Text find operation uses Perl Compatible Regular Expressions (PCRE).

Upvotes: 0

Views: 48

Answers (1)

Keith Hall
Keith Hall

Reputation: 16065

You could use

get :\w+(?:,\n?[^\n,]+)+

Demo

  • get : literal
  • \w+ one or more word characters
  • (?: begin sub-expression
    • , literal
    • \n? an optional newline
    • [^\n,]+ at least one character that isn't a newline or a comma
  • )+ match this sub-expression at least once

Upvotes: 1

Related Questions