I have been using strscan till version 0.65 and it was working with a
code like this but now trying to upgrade to ruby 1.8 it doesn’t, is
there a bug in strscan or I misunderstood it ?
I expect to find a match for the regular expression but it doesn’t.
#---- code start here
require ‘strscan’
SSI_search_re = /|[)(.+?)(]/m
def parse(html)
ret_var = ''
ssc = StringScanner.new(html)
ret_var << "\n0print(' xxx start scanner zzz ')\n"
while ssc.scan(SSI_search_re) do
ret_var << "\n1print([}#{ssc.pre_match}{])\n"
if ssc[1]
ret_var << ' :: ' + ssc[1]
else
ret_var << "\n2print(#{ssc[2]})\n"
end
end
ret_var << "\n3print([}#{ssc.rest}{])\n"
ret_var << "\n4print(' vvv end scanner kkk ')\n"
end
res = parse(‘Hello
[)Domingo(] !’)
puts res
#---- code end here
Hi,
I have been using strscan till version 0.65 and it was working with a
code like this but now trying to upgrade to ruby 1.8 it doesn’t, is
there a bug in strscan or I misunderstood it ?
StringScanner has the “cursor” internally, and always tries
matching at the position. In other words, it never skip
unmatched portion.
SSI_search_re = /|[)(.+?)(]/m
res = parse(‘Hello
[)Domingo(] !’)
This string doesn’t start with the part matches to the RE.
SSI_search_re = /.*?(?:|[)(.+?)(])/m
may works but I’m not sure if it is what you really want.
···
At Tue, 19 Aug 2003 20:03:28 +0900, Domingo Alvarez Duarte wrote:
–
Nobu Nakada
Hi,
In mail “Strscan ruby 1.8 why this doesn’t work ?”
I have been using strscan till version 0.65 and it was working with a
code like this but now trying to upgrade to ruby 1.8 it doesn’t, is
there a bug in strscan or I misunderstood it ?
Did you use Ruby version of StringScanner? Try
$ ruby -rstrscan -e ‘p StringScanner’
with 0.6.5. If it prints “StringScanner_R”, it is Ruby version.
otherwise (“StringScanner_C”) it is C version.
Ruby version and C version is completely different,
and C version is bundled with ruby 1.8.
I expect to find a match for the regular expression but it doesn’t.
#---- code start here
require ‘strscan’
SSI_search_re = /|[)(.+?)(]/m
def parse(html)
ret_var = ‘’
ssc = StringScanner.new(html)
ret_var << “\n0print(’ xxx start scanner zzz ')\n”
while ssc.scan(SSI_search_re) do
while ssc.scan_until(SSI_search_re) do
might help.
Regards,
Minero Aoki
···
domingo@dad-it.com (Domingo Alvarez Duarte) wrote:
nobu.nokada@softhome.net wrote in message news:200308191153.h7JBrIb7031508@sharui.nakada.kanuma.tochigi.jp…
Hi,
I have been using strscan till version 0.65 and it was working with a
code like this but now trying to upgrade to ruby 1.8 it doesn’t, is
there a bug in strscan or I misunderstood it ?
StringScanner has the “cursor” internally, and always tries
matching at the position. In other words, it never skip
unmatched portion.
SSI_search_re = /|[)(.+?)(]/m
res = parse(‘Hello
[)Domingo(] !’)
This string doesn’t start with the part matches to the RE.
SSI_search_re = /.*?(?:|[)(.+?)(])/m
may works but I’m not sure if it is what you really want.
No it’s not that, I think it should try match the whole string and not
only if it starts with the regular expression and as I told and you
can try it works with strscan version 6.5 but not with 6.7 as well, I
couldn’t find any documentation that try explain how it should work in
ruby 1.8.
···
At Tue, 19 Aug 2003 20:03:28 +0900, > Domingo Alvarez Duarte wrote: