forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiguelex.cpp
65 lines (54 loc) · 2.05 KB
/
miguelex.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <string>
#include <regex>
void regExpr(std::string cadena) {
std::regex patron(R"-(-?\d+(\.\d+)?)-");
std::smatch numeros;
std::cout << "Números encontrados:" << std::endl;
while (std::regex_search(cadena, numeros, patron)) {
std::cout << numeros.str() << std::endl;
cadena = numeros.suffix();
}
std::cout << std::endl;
}
void emailValidation(const std::string& email) {
std::regex patron(R"-([a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})-");
if (std::regex_match(email, patron)) {
std::cout << "El email " << email << " es válido." << std::endl;
} else {
std::cout << "El email " << email << " no es válido." << std::endl;
}
}
void phoneValidation(const std::string& phone) {
std::regex patron(R"-((\+?\d{2,3})?[-. ]?\d{9})-");
if (std::regex_match(phone, patron)) {
std::cout << "El teléfono " << phone << " es válido." << std::endl;
} else {
std::cout << "El teléfono " << phone << " no es válido." << std::endl;
}
}
void urlValidation(const std::string& url) {
std::regex patron(R"-((http|https):\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})-");
if (std::regex_match(url, patron)) {
std::cout << "La URL " << url << " es válida." << std::endl;
} else {
std::cout << "La URL " << url << " no es válida." << std::endl;
}
}
int main() {
std::string texto = "Este es un texto con números como 123, 45.6, -7 y 1000.";
std::cout << "Vamos a analizar el siguiente texto:" << std::endl;
std::cout << "'" << texto << "'\n\n";
regExpr(texto);
texto = "123Erase una vez un número 1234567890 y otro 0987654321. Y para terminar456";
std::cout << "Vamos a analizar el siguiente texto:" << std::endl;
std::cout << "'" << texto << "'\n\n";
regExpr(texto);
emailValidation("[email protected]");
emailValidation("correo@correo");
phoneValidation("+34 123456789");
phoneValidation("123456789");
urlValidation("http://www.google.com");
urlValidation("www.google.com");
return 0;
}