Hi,
is there a possibility to return all the matches of a regexp? or in
other words is there a way to apply a block to all matches at once?
Something like String#gsub but where I can specifiy what to do with the
matches…
Thanks
Andi
Hi,
is there a possibility to return all the matches of a regexp? or in
other words is there a way to apply a block to all matches at once?
Something like String#gsub but where I can specifiy what to do with the
matches…
Thanks
Andi
On 12/11/06, Andi S. [email protected] wrote:
is there a possibility to return all the matches of a regexp? or in
other words is there a way to apply a block to all matches at once?
Something like String#gsub but where I can specifiy what to do with the
matches…
These things are actually two different things.
-austin
On 11.12.2006 22:26, Andi S. wrote:
is there a possibility to return all the matches of a regexp? or in
other words is there a way to apply a block to all matches at once?
Something like String#gsub but where I can specifiy what to do with the
matches…
What exactly do you want to do with matches?
robert
On Dec 11, 2006, at 4:50 PM, Andi S. wrote:
robert
I’d like to build a small web-tool for myself to highlight all the
matches of a regexp against a specified string (e.g. the matches
should
be in a different color). But I think I found a solution:source_string.gsub(regexp) {|match| “<span
style=“color:red;”>#{match}”}
You don’t really need the block form for such a simple replacement.
This is the same thing:
source_string.gsub(regexp, ‘&’)
James Edward G. II
Robert K. wrote:
On 11.12.2006 22:26, Andi S. wrote:
is there a possibility to return all the matches of a regexp? or in
other words is there a way to apply a block to all matches at once?
Something like String#gsub but where I can specifiy what to do with the
matches…What exactly do you want to do with matches?
robert
I’d like to build a small web-tool for myself to highlight all the
matches of a regexp against a specified string (e.g. the matches should
be in a different color). But I think I found a solution:
source_string.gsub(regexp) {|match| “<span
style=“color:red;”>#{match}”}
On 11.12.2006 23:56, James Edward G. II wrote:
source_string.gsub(regexp, ‘&’)
… and in fact more efficient IIRC.
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs