TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

What are your Ruby Regex Idioms?

30 pointsby rahulvohraover 15 years ago

6 comments

sant0sk1over 15 years ago
I use Rubular all the time for testing my regexes with ease. Give it a shot, its really well done:<p><a href="http://rubular.com/" rel="nofollow">http://rubular.com/</a>
评论 #968219 未加载
nanijoeover 15 years ago
This (ruby) regex thing still gives me a headache , esp when I'm trying to figure out other people's code
评论 #968441 未加载
评论 #968459 未加载
评论 #968242 未加载
sofalover 15 years ago
One of my favorite patterns:<p><pre><code> _, username, domain = */([^@]+)@(.+$)/.match("foo@example.com")</code></pre>
评论 #967930 未加载
评论 #967921 未加载
iamwilover 15 years ago
I didn't see it mentioned, but, btw, this code allows a method to introspect to figure out what the method name that's currently being executed.<p>caller[0][/`([^']*)'/, 1]<p>Note that you only need to do this for Ruby 1.8. In Ruby 1.9, there will be a __method__() and __callee__() method that does the same thing.
zzleeperover 15 years ago
Woah.. I want that for Python..
评论 #968041 未加载
grandalfover 15 years ago
<p><pre><code> (foo){2,5}</code></pre>