Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2088
| X-FeedAbuse | http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.16.109 |
|---|---|
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!nospam.fr.eu.org!talisker.lacave.net!lacave.net!not-for-mail |
| From | Ruby Ruby <ruby@ayni.com> |
| Newsgroups | comp.lang.ruby |
| Subject | Unwanted collector in regular expression |
| Date | Fri, 1 Apr 2011 02:20:10 -0500 |
| Organization | Service de news de lacave.net |
| Lines | 49 |
| Message-ID | <10d78ef55fdd56f820bd1bef075b3562@ruby-forum.com> (permalink) |
| NNTP-Posting-Host | bristol.highgroove.com |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 7bit |
| X-Trace | talisker.lacave.net 1301642615 80067 65.111.164.187 (1 Apr 2011 07:23:35 GMT) |
| X-Complaints-To | abuse@lacave.net |
| NNTP-Posting-Date | Fri, 1 Apr 2011 07:23:35 +0000 (UTC) |
| X-Received-From | This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway |
| X-Mail-Count | 380733 |
| X-Ml-Name | ruby-talk |
| X-Rubymirror | Yes |
| X-Ruby-Talk | <10d78ef55fdd56f820bd1bef075b3562@ruby-forum.com> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.ruby:2088 |
Show key headers only | View raw
Hi every
installation here ruby-1.8.6.420-2.fc13.x86_64
i wanted to highlight some text fields (change background color) in an
xhtml page. To do that, i had to skip all xhtml markup, 'cause it is not
advisable to put markup into markup.
i created the following function:
<snip>
def highlight(what, crix)
if crix.empty? then return what end
@tix.puts "WHAT: "+what
ccir = Regexp.new("(?:\<[^\>]+\>)|(?:("+crix.join("|")+"))", "i")
return what.gsub(ccir) {|s|
@tix.puts "COLL: "+s
if ! s.empty? && ! s.match(/^\</)
"<span style='background-color:"+CCOL+";'>"+s+"</span>"
else s
end
}
end # highlight
</snip>
the main part of the function is the ccir regular expression.
my thinking was, that with the first group in the regular expression i
would skip all markup, and with the second group in the regular
expression i would collect the fields designated in the crix array.
When the first group of the regular expression matches, i was awaiting
an empty string to be returned to the block, otherwise the element to be
highlighted would be returned to the block.
NOPE.
when the first group of the regular expression matched, the test file
showed me, that an entire markup sequence was returned to the block,
even if no collector was active in the first group. when the second
group of the regular expression matched, it returned the expected string
to the block.
this is why i had to avoid the markup-in-markup by checking again in the
block if the string returned to the block started with "<", i.e. if it
was markup.
so be warned, if you use groups in regular expressions, as they may not
return what you expected.
suomi
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Next in thread | Find similar | Unroll thread
Unwanted collector in regular expression Ruby Ruby <ruby@ayni.com> - 2011-04-01 02:20 -0500 Re: Unwanted collector in regular expression Brian Candler <b.candler@pobox.com> - 2011-04-01 03:17 -0500 Re: Unwanted collector in regular expression Robert Klemme <shortcutter@googlemail.com> - 2011-04-01 03:23 -0500
csiph-web