1

I have this regex

@(.*)\((.*)\)

And I'm trying to get two matches from this string

@YouTube('dqrtLyzNnn8') @Vimeo('124719070')

I need it to stop after the closing ), so I get two matches instead of one.

See example on Regexr

3 Answers3

3

Be lazy (?):

@(.*?)\((.*?)\)

DEMO

Nir Alfasi
  • 51,812
  • 11
  • 81
  • 120
0

You may use a negated character class:

@([^()]+)\(([^()]+)\)
Toto
  • 86,179
  • 61
  • 85
  • 118
0

Your regex is trying to eat as much characters as possible. Look at the next regex:

echo "@YouTube('dqrtLyzNnn8') @Vimeo('124719070')" | 
   sed 's/@[a-zA-Z]*(\([^)]*\)[^@]*@[a-zA-Z]*(\([^)]*\).*/\1 \2/'

I do not know the exact requirements, you might me easier of starting with another command:

echo "@YouTube('dqrtLyzNnn8') @Vimeo('124719070')"  | cut -d\' -f2,4
Walter A
  • 17,923
  • 2
  • 22
  • 40