From: Zach Dennis Date: 2005-01-18T06:27:29+09:00 Subject: Re: My regexp stupidity needs assistance before loose all my hair! Zach Dennis wrote: > trans. (T. Onoma) wrote: > >> Let me painfully honest: I hate parsing, especially w/ regexp, and I >> don't care if it's because I stupid and suck at it. It shouldn't have >> to be this hair pulling! Anyway... Can some one please give the >> regular expression to match the first square bracket's contents. In >> this case it would be "Hello". >> >> s = <<-EOS >> [Hello] >> This [b]is[b.] a test. >> [Hello.] >> EOS > > > The trick here is to make sure you are non-greedy. > > s =~ /\[([^\]]*)\]/ Almost forgot, $1 is the match you are looking for. > Zach