Hi All
I’m trying to filter email adresses like this
#! /usr/bin/ruby
email = “test_test.test”
if email.scan(/@/)
p “yes”
end
For some reason my program always prints ‘yes’
How would should I do this ?
thnx
LuCa
Hi All
I’m trying to filter email adresses like this
#! /usr/bin/ruby
email = “test_test.test”
if email.scan(/@/)
p “yes”
end
For some reason my program always prints ‘yes’
How would should I do this ?
thnx
LuCa
On Jul 20, 10:15 am, Luca S. [email protected] wrote:
end
For some reason my program always prints ‘yes’
How would should I do this ?
thnx
LuCaPosted viahttp://www.ruby-forum.com/.
so if email.scan(/@/) is always true
Hi –
On Sun, 20 Jul 2008, Luca S. wrote:
doesn’t work
str =~ /@/
It’s absolutely not a robust way to check for an email address, but it
will check for an at-sign
As for /[^pattern]/, that will match one character that is not a, e,
n, p, t, or r. For non-matching, try:
str !~ /pattern/
or maybe negative assertions in the regex.
David
David A. Black wrote:
Hi –
On Sun, 20 Jul 2008, Luca S. wrote:
doesn’t work
str =~ /@/
thnx, I was looking for a String#method but this is OK too
As for /[^pattern]/, that will match one character that is not a, e,
n, p, t, or r. For non-matching, try:
my mistake
thnx a lot
LuCa
Hi –
On Sun, 20 Jul 2008, Luca S. wrote:
thnx, I was looking for a String#method but this is OK too
=~ is a String method.
Match---If _obj_ is a +Regexp+, use it as a pattern to match
against _str_,and returns the position the match starts, or +nil+
if there is no match. Otherwise, invokes _obj.=~_, passing _str_
as an argument. The default +=~+ in +Object+ returns +false+.
"cat o' 9 tails" =~ /\d/ #=> 7
"cat o' 9 tails" =~ 9 #=> false
David
you’re right (I still have to get used to that!)
thnx, makes sense
How do you, BTW, exlude matches ?
!str.scan(pattern) do
…
end
doesn’t work. Also a regex like
/[^pattern]/
doesn’t work
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