The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
The Slice Matcher

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
The Slice Matcher Posted: Jan 6, 2006 6:13 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: The Slice Matcher
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

String#[] and slice both hand you back matches, right?

 >> "redhanded.hobix.com:80"[/:\d+$/]
 => ":80" 
 >> "Matching Mole -- Little Red Record".slice(/Mo\w+/)
 => "Mole" 

But it’s no good for getting back match groups.

 >> "02. One of Us is Dead.mp3"[/^\d+\. (.*)\.mp3$/]
 => "02. One of Us is Dead.mp3" 

Oh, no, wait, it is so good at it!

 >> "02. One of Us is Dead.mp3"[/^\d+\. (.*)\.mp3$/, 1]
 => "One of Us is Dead" 

Credit due: Found this while admiring flgr’s one-line fantastic web server he left in the comments several months ago:

 require'socket';s=TCPServer.new 80;loop{c=s.accept;c<<"\n"+IO.read(
 c.gets[/\/(.*) /,1].gsub(/\.{2,}/){})rescue 404;c.close}

Read: The Slice Matcher

Topic: Enterprise Is Not an Insult Previous Topic   Next Topic Topic: Heh, Mmmnn, Perl People

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use