iMelody Ooo wrote:
> I want to match last chars of the line,
> 
> def show_regexp(a,re)
>   if a =~ re
>     "#{$`}<<#{$&}>>#{$'}"
>   else
>     "no match"
>   end
> end
> 
> puts show_regexp("abc as;",/^a/)
> puts show_regexp("abc as;",/as$/)
> puts show_regexp("abc as;",/\zas/)
> puts show_regexp("abc as;",/\Zas/)
> puts show_regexp("abc as;",/(.*)as$/)
> puts show_regexp("abc as;",/(.*)\zas/)
> puts show_regexp("abc as;",/(.*)\Zas/)
> 
> Result:
> <<a>>bc as;
> no match
> no match
> no match
> no match
> no match
> no match

i see that you are actually wanting to match "as" at the end of 
line/string. There is no need to use regexp.

irb(main):001:0> s="abc as;"
=> "abc as;"
irb(main):002:0> s[-2,2]=="as"
=> false



-- 
Posted via http://www.ruby-forum.com/.