Brad
Brad

Reputation: 2237

Need a RegEx that will match a name="value"

Here's what I have so far, I'm not a regex expert by any means....
I need to be able to match globally. (/g)

total-matched=\"([^\"]*)\"


total-matched="1618"
total-matched= "1618" 
total-matched ="1618" 
total-matched = "1618"
total-matched='1618'
total-matched= '1618'
total-matched ='1618'
total-matched = '1618'

Upvotes: 0

Views: 37

Answers (1)

Barmar
Barmar

Reputation: 781503

total-matched\s*=\s*(["'])(.*?)\1
  • total-matched - matched literally
  • \s* - optional whitespace before =
  • = - matched literally
  • \s* - optional whitespace after =
  • (["']) - match either type of quote, and remember it as \1
  • (.*?) - non-greedy match for any text, captured as group 2
  • \1 - match the same kind of quote we matched earlier

Upvotes: 2

Related Questions