regular expression java code example
Example 1: regular expression java
^(.+)@(.+)$ "^(.+)@(.+)$\""
^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$
^[\\w!#$%&'*+/=?`{|}~^-]+(?:\\.[\\w!#$%&'*+/=?`{|}~^-]+)*@(?!-)(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$
Example 2: java regex
import java.util.regex.*;
public class RegexExample1{
public static void main(String args[]){
Pattern p = Pattern.compile(".s");
Matcher m = p.matcher("as");
boolean b = m.matches();
boolean b2=Pattern.compile(".s").matcher("as").matches();
boolean b3 = Pattern.matches(".s", "as");
System.out.println(b+" "+b2+" "+b3);
}}
Example 3: java regex matcher example
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class MatcherExample {
public static void main(String[] args) {
String text =
"This is the text to be searched " +
"for occurrences of the http:// pattern.";
String patternString = ".*http://.*";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(text);
boolean matches = matcher.matches();
int count = 0;
while(matcher.find()) {
count++;
System.out.println("found: " + count + " : "
+ matcher.start() + " - " + matcher.end());
}
}
}
Example 4: lambda expression java
public class TestLambda {
public static void main(String args[]) {
List<String> lowerCaseStringsList = Arrays.asList("a","b","c");
List<String> upperCaseStringsList = lowerCaseStringsList.stream().
map(String::toUpperCase).
collect(Collectors.toList());
}
}
Example 5: regex java
import java.io.*;
import java.util.regex.*;
public class testRegex {
private static Pattern pattern;
private static Matcher matcher;
public static void main(String args[]) {
pattern = Pattern.compile("Hugo");
matcher = pattern.matcher("Hugo Etiévant");
while(matcher.find()) {
System.out.println("Trouvé !");
}
}
}