Tag "RegExp" (5)
Java: Get quoted string regex java
Get quoted string regex java ... Reveal Code
String REGEX = "\"([^\"]*)\"";
String sentence = "World \"Hello\" World!";
Pattern pattern = Pattern.compile(REGEX);
Matcher matcher = pattern.matcher(sentence);
if(matcher.find()){
String result = matcher.group(1);
System.out.println(result);
} else {
System.out.println("Nothing");
}
takes a float number ... Reveal Code
#include
#include
#include
#include
int main() {
std::string str = "-3.14asd.asd.a0.23.asdfj234d.123.34++23.0";
boost::regex rgx("\\-?\\d+\\.\\d+");
std::copy(
boost::sregex_token_iterator(str.begin(), str.end(), rgx),
boost::sregex_token_iterator(),
std::ostream_iterator (std::cout, " ")
);
getchar();
}
PHP: Allow only numbers and letters
Allow only numbers and letters using preg_match ... Reveal Code
if (!preg_match("/^[a-zA-Z0-9-\s]{3,24}$/", $_REQUEST[user_name])) {
$errormsg .= "Use only letters and numbers";
}
JavaScript: Email validation
Validation of the entered email using regex ... Reveal Code
function IsEmail(email) {
var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return regex.test(email);
}
PHP: Email validation
Validation of the entered email using preg_match ... Reveal Code
if (!preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$/', $_REQUEST[user_email])) {
$errmsg .= "Please enter a valid email address
";
}