Answers for "regular expression java"

1

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());
        }
    }
}
Posted by: Guest on December-21-2020
8

java regex

import java.util.regex.*;  
public class RegexExample1{  
public static void main(String args[]){  
//1st way  
Pattern p = Pattern.compile(".s");//. represents single character  
Matcher m = p.matcher("as");  
boolean b = m.matches();  
  
//2nd way  
boolean b2=Pattern.compile(".s").matcher("as").matches();  
  
//3rd way  
boolean b3 = Pattern.matches(".s", "as");  
  
System.out.println(b+" "+b2+" "+b3);  
}}
Posted by: Guest on September-26-2020
2

regular expression java

//Ther are three type of REGULAR EXPRESSION     
   //first
   ^(.+)@(.+)$   "^(.+)@(.+)$\""
   //second
   ^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$
     //third
   ^[\\w!#$%&'*+/=?`{|}~^-]+(?:\\.[\\w!#$%&'*+/=?`{|}~^-]+)*@(?!-)(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$
Posted by: Guest on June-08-2021
1

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é !");
        }
    }
}
Posted by: Guest on February-05-2021
0

lambda expression java

public class TestLambda {

   public static void main(String args[]) {
      List<String> lowerCaseStringsList = Arrays.asList("a","b","c");
     // the :: notation is the lambda expression
     // it's the same as the anonymous function s -> s.toUpperCase()
      List<String> upperCaseStringsList = lowerCaseStringsList.stream().
        map(String::toUpperCase).
        collect(Collectors.toList());
   }   
}
Posted by: Guest on January-30-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language