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
  • 53,191
  • 11
  • 86
  • 129
0

You may use a negated character class:

@([^()]+)\(([^()]+)\)
Toto
  • 89,455
  • 62
  • 89
  • 125
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
  • 19,067
  • 2
  • 23
  • 43