Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[RUBY] Get Vowels using regex
04-16-2010, 06:16 AM
Post: #1
[RUBY] Get Vowels using regex
Code:
#!/usr/bin/env ruby

#Scans for vowels
print "Enter in a Sentence: "
n = gets
#Get user input
p = n.scan(/[aeiouAEIOU]/)  { |y| puts y}
# Create variable p scan the string n for chars with 'aeiouAEIOU' then puts them into variable y
#then prints y

"Character is determined more by the lack of certain experiences than by those one has had."
Friedrich Nietzsche
Visit this user's website Find all posts by this user
Quote this message in a reply
04-16-2010, 06:25 AM
Post: #2
RE: [RUBY] Get Vowels using regex
Great code Back_track !
Very good !

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
04-16-2010, 08:57 AM
Post: #3
RE: [RUBY] Get Vowels using regex
You'll be seeing alot more of things like this, I'm taking up ruby. And thinking of learning Python also!

"Character is determined more by the lack of certain experiences than by those one has had."
Friedrich Nietzsche
Visit this user's website Find all posts by this user
Quote this message in a reply
04-16-2010, 06:29 PM
Post: #4
RE: [RUBY] Get Vowels using regex
Good choice for Python, but i am not much of a Ruby lover.
I know something in Python, but not much and i am also interested in learning more.

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
04-18-2010, 11:10 AM
Post: #5
RE: [RUBY] Get Vowels using regex
Nice work I look at ruby a couple times since I been here. It is alright but some of the syntax I cannot stand. Python wins for me but I guess it depends on your style Smile
Find all posts by this user
Quote this message in a reply
04-18-2010, 07:07 PM
Post: #6
RE: [RUBY] Get Vowels using regex
Yeah codecaine, every programmer has it's own style and programming languages that he likes because of syntax.

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
04-20-2010, 08:00 AM
Post: #7
RE: [RUBY] Get Vowels using regex
(/[aeiou]/i) for no casesensitivity
(04-16-2010 06:16 AM)Back_track Wrote:  
Code:
#!/usr/bin/env ruby

#Scans for vowels
print "Enter in a Sentence: "
n = gets
#Get user input
p = n.scan(/[aeiouAEIOU]/)  { |y| puts y}
# Create variable p scan the string n for chars with 'aeiouAEIOU' then puts them into variable y
#then prints y
Find all posts by this user
Quote this message in a reply
04-20-2010, 10:12 AM
Post: #8
RE: [RUBY] Get Vowels using regex
(04-20-2010 08:00 AM)codecaine Wrote:  (/[aeiou]/i) for no casesensitivity
(04-16-2010 06:16 AM)Back_track Wrote:  
Code:
#!/usr/bin/env ruby

#Scans for vowels
print "Enter in a Sentence: "
n = gets
#Get user input
p = n.scan(/[aeiouAEIOU]/)  { |y| puts y}
# Create variable p scan the string n for chars with 'aeiouAEIOU' then puts them into variable y
#then prints y
Oh, so 'i' is just searching for all forms of those character(s)?

"Character is determined more by the lack of certain experiences than by those one has had."
Friedrich Nietzsche
Visit this user's website Find all posts by this user
Quote this message in a reply
04-21-2010, 04:52 AM
Post: #9
RE: [RUBY] Get Vowels using regex
yea so you only have to type the characters in lowercase or uppercase.
(04-20-2010 10:12 AM)Back_track Wrote:  
(04-20-2010 08:00 AM)codecaine Wrote:  (/[aeiou]/i) for no casesensitivity
(04-16-2010 06:16 AM)Back_track Wrote:  
Code:
#!/usr/bin/env ruby

#Scans for vowels
print "Enter in a Sentence: "
n = gets
#Get user input
p = n.scan(/[aeiouAEIOU]/)  { |y| puts y}
# Create variable p scan the string n for chars with 'aeiouAEIOU' then puts them into variable y
#then prints y
Oh, so 'i' is just searching for all forms of those character(s)?
Find all posts by this user
Quote this message in a reply
01-05-2014, 04:21 PM (This post was last modified: 01-05-2014 04:26 PM by codecaine.)
Post: #10
RE: [RUBY] Get Vowels using regex
Here is a python version I did.
Code:
import re #import regex module
name = 'codecaine' #username
count = len(re.findall(r'[aeiou]',name,re.IGNORECASE)) #ignore case & find all vowels in username then return the total count of vowels from the results found
print 'There are this many vowels in your string:', count #print result
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: