I need at the end just thatstrue. So I wrote for the beginning:
result = overlook.scan(/myoverlook://(.+?)\n/m)
Of course this doesn’t work because of the // which are special
charachters in a regexpr. But how can I tell that they shoudln’t be
treated as specialcharachters? Is there an escape charachter? I tried it
so:
result = overlook.scan(/myoverlook:\/\/\(.+?)\n/m)
but this throws an error: unmatched ): /myoverlook://(.+?)\n/
result = overlook.scan(/myoverlook:\/\/\(.+?)\n/m)
That would be correct if you hadn’t accidentally escaped the (, too.
A cleaner way would be to use %r{} instead of //, so that / isn’t
treated as a
special character and you don’t need to escape it. Like so:
result = overlook.scan(%r{myoverlook://(.+?)\n}m)
result = overlook.scan(/myoverlook:\/\/\(.+?)\n/m)
That would be correct if you hadn’t accidentally escaped the (, too.
A cleaner way would be to use %r{} instead of //, so that / isn’t treated as a
special character and you don’t need to escape it. Like so:
result = overlook.scan(%r{myoverlook://(.+?)\n}m)
I’d also change the RX to a more appropriate one, e.g. any of these
%r{myoverlook://(\w+)@}
%r{myoverlook://([^@]+}
You can then extract the part you are looking for from group 1.
Depends on the surrounding context which of the RX is better suited.
I’d probably prefer the fist one since it is more robust.
Kind regards
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.