Created
May 28, 2014 14:03
-
-
Save andrei512/ba22232ad840d82f169e to your computer and use it in GitHub Desktop.
get some phone mumbers :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
content = "Titlu stiintific: , Forma de exercitare a profesiei: CI, Modalitatea de exercitare a profesiei: T | |
Sediul profesional secundar: , Birou de lucru: | |
Telefon fix: , Telefon mobil: 0723384846, Fax: , E-mail: | |
Sediul profesional secundar: , Birou de lucru: | |
Telefon fix: 0263684846, Telefon mobil: 0723384846, Fax: , E-mail: | |
0723384 | |
0723384846 | |
072338484 | |
0263384846" | |
class String | |
def all_matches pattern, &callback | |
all_matches = [] | |
string = self | |
while string != nil and string.length > 0 | |
match_data = string.match(pattern) | |
if match_data != nil | |
if match_data.captures.count == 0 | |
break | |
end | |
match_data.names.zip(match_data.captures).each do |k,v| | |
if v | |
all_matches << { | |
k => v | |
} | |
end | |
end | |
string = match_data.post_match | |
else | |
break | |
end | |
end | |
all_matches | |
end | |
end | |
pattern = /(Telefon\s*fix:\s*(?<phone>02\d{8}))|(Telefon\s*mobil:\s*(?<mobile>07\d{8}))/ | |
puts content.all_matches(pattern) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment