G
Gregory Brown
It reminds me of a saying: "If you throw a rock into a pack of dogs, the
dog that yelps loudest is the one that got hit."
That's the point you missed. Rubyists don't throw rocks at dogs.
It reminds me of a saying: "If you throw a rock into a pack of dogs, the
dog that yelps loudest is the one that got hit."
Gregory said:That's the point you missed. Rubyists don't throw rocks at dogs.
That's just 'cause Ruby rocks are too expensive to throw ;-)Gregory said:That's the point you missed. Rubyists don't throw rocks at dogs.
Jeff said:Quite simply, Ruby is *supposed* to be about consistency ... Having the
"everything is an object, principal of least surprise" mantra, then
using these which act like a global ( $ ) but aren't actually ( local
scope ) is just vile.
I never called out anyone in particular, didn't have anyone in mind in
fact, but it's funny how some people are insecure enough that they're
getting offended by what I wrote, and getting so defensive that they
feel the need to lash out in return.
It reminds me of a saying: "If you throw a rock into a pack of dogs, the
dog that yelps loudest is the one that got hit."
I'm kind of new here, but it seems like debating the quality of one
another's rudeness is slightly OT.
My point is this: I am (or was) a Perl programmer and I do not like the
"Perlish" syntax one bit. I didn't like it in Perl, and I don't like it
in Ruby either. However, I object to the notion that Perlishness makes
it offensive. Non-obviousness is what makes it offensive. The matcher
syntax is much clearer.
Gregory Brown said:That's the point you missed. Rubyists don't throw rocks at dogs.
ako... said:yes, thank you. this is a better description of the problem. i am not
a native english speaker, so may be this is one of the reasons why my
question is not clear.
i saw a solution to this problem that uses split at the end. it of
course won't work if you change your example and allow quoted strings
in source-words and destination-words. a quoted string can contain
anything, spaces too and your keywords too, so the subsequent split
won't work.
well, i did not realise that the term "group's captures" is that rare.
i thought it was a standard term. but may be i am brainwashed by
microsoft. so i have this code in .net which might help to clarify
what i am talking about:
string text = "One car red car blue car";
string pat = @"^(?\w+)\s+)*(\w+)$";
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
// Match the regular expression pattern against a text
string.
Match m = r.Match(text);
if (m.Success)
{
Console.WriteLine("match: [{0}]", m);
foreach (Group g in m.Groups)
{
Console.WriteLine("group: [{0}]", g);
foreach (Capture c in g.Captures)
{
Console.WriteLine("\tcapture: [{0}]", c);
}
}
}
the output is:
match: [One car red car blue car]
group: [One car red car blue car]
capture: [One car red car blue car]
group: [blue]
capture: [One]
capture: [car]
capture: [red]
capture: [car]
capture: [blue]
group: [car]
capture: [car]
as you see, the first group is $0, the second group is $1, and the
third is $2. but $1 and $2 contain captures too. it is like if $1 and
$2 were arrays in Ruby.
in my opinion this is a big limitation of ruby's regular expressions.
it just must be as powerful as .net ; -)
konstantin
=> ["ne", "ar", "ed", "ar", "lue", "ar"]s.scan(/\w(\w+)/).map{|m| m[0]}
=> ["ne", "ar", "ed", "ar", "lue", "ar"]ma=[] => []
s.scan(/\w(\w+)/) {|m| ma << m[0]} => "One car red car blue car"
ma
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.