On Wed, Aug 29, 2012 at 3:48 AM, Regis d'Aubarede <[email protected]> wrote:
>> re = /@\[Subject:\d+\|(.*)\]/
>
> try :
> re = /@\[Subject:\d+\|(.*?)\]/
>
> test :
> str2.scan re
> => [["My_Subject"], ["Your_Subject"]]
In this case we can also use a character class which excludes closing
square bracket:
irb(main):004:0> [str1,str2].each {|s| printf "%s -> %p\n", s,
s.scan(/\[Subject:\d+\|([^\]]*)\]/)}
Hi, @[Subject:13|My_Subject] -> [["My_Subject"]]
Hi, @[Subject:13|My_Subject], and @[Subject:45|Your_Subject] ->
[["My_Subject"], ["Your_Subject"]]
irb(main):005:0> [str1,str2].each {|s| printf "%s -> %p\n", s,
s.scan(/\[Subject:\d+\|([^\]]*)\]/).flatten}
Hi, @[Subject:13|My_Subject] -> ["My_Subject"]
Hi, @[Subject:13|My_Subject], and @[Subject:45|Your_Subject] ->
["My_Subject", "Your_Subject"]
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en