------ art_1006_18479206.1213820839711 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Perfect. Thanks Kyle & Sebastian. On Wed, Jun 18, 2008 at 4:17 PM, Kyle Schmitt <kyleaschmitt / gmail.com> wrote: > On Wed, Jun 18, 2008 at 3:05 PM, Petr Dupovnik <petrdupovnik / gmail.com> > wrote: > > Hello > > > > Suppose I have a string with some repeating patterns: > > > > string some miscellaneous text [sdfsdf.wer], some more miscellaneous > text > > [vbnfg.thy], and yet more text [jkhjkhjk.345]" > > > > I want catch all instances of "[.*]" in this line - without the square > > brackets. - in the above example that would be 'sdfsdf.wer', 'vbnfg.thy', > > and 'jkhjkhjk.345'. > string.scan /(\[[^\]]*\])/ > would do the trick > ..although you could also use split with that same regex if you needed > the rest of the data for something. > > scan is only keeping the saved part of the regex, as marked by our > parenthesies > Inside of them is the slightly ugly statement > \[[^\]*]\] > since brackets are special in regexs, we have to escape them first, > hence the \[ and \] stuff > So it matches one bracket, [, and anything that isn't another bracket, > ], followed by one bracket, ]. > > Does that make sense? > > --Kyle > > ------ art_1006_18479206.1213820839711--