Answers for "java regex"

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

regex java

public class Regex {
	public static void main(String[] args) {
		System.out.println("IPv4: " + ipv4Adresse("192.168.100.1"));
		System.out.println("IPv6: " + ipv6Adressen("2001:0db8:85a3:08d3:1319:8a2e:0370:7344"));
		System.out.println("MAC-Adresse: " + macAdressen("88:66:5a:44:a9:12"));
		System.out.println("Flugnummer: " + flugNummer("AIR2D3E"));
		System.out.println("Zahlen: " + zahlen("123.3123123"));
		System.out.println("Datum: " + datum("31.12.2021"));
		System.out.println("Kennzeichen: " + kennzeichen("WE-12FR")); // XX-XXXX oder X-XXXXXX Leerzeichen muss angegeben werden
		System.out.println("E-Mail Adressen: " + emailAdressen("[email protected]"));
	}

	public static boolean ipv4Adresse(String ipAdresse) {
		Pattern pattern = Pattern.compile("^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})$", Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher(ipAdresse);
		return matcher.find();
	}

	public static boolean ipv6Adressen(String ipAdresse) {
		Pattern pattern = Pattern.compile("^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$", Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher(ipAdresse);
		return matcher.find();
	}

	public static boolean macAdressen(String macAddress) {
		Pattern pattern = Pattern.compile("((?:[a-zA-Z0-9]{2}[:-]){5}[a-zA-Z0-9]{2})", Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher(macAddress);
		return matcher.find();
	}

	public static boolean flugNummer(String flugnummer) {
		Pattern pattern = Pattern.compile("(^[A-Z]{2,3})([\\w\\d]{2,4}$)", Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher(flugnummer);
		return matcher.find();
	}

	public static boolean zahlen(String nummer) {
		Pattern pattern = Pattern.compile("(^[\\d]+$)|(^[\\d.\\d]+$)", Pattern.CASE_INSENSITIVE);
		//String meinString = Double.toString(nummer);
		Matcher matcher = pattern.matcher(nummer);
		return matcher.find();
	}

	public static boolean datum(String datum) {
		Pattern pattern = Pattern.compile("^(?<day>1[0-9]|2[0-9]|3[0-1]).(?<month>1[0-2]|0[1-9]).(?<year>[0-9]{4})$", Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher(datum);
		return matcher.find();
	}

	public static boolean kennzeichen(String kennzeichen) {
		Pattern pattern = Pattern.compile("(^[A-Z]{1,2}-\\d\\w{3,5}$)", Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher(kennzeichen);
		return matcher.find();
	}

	public static boolean emailAdressen(String emailAdressen) {
		Pattern pattern = Pattern.compile("^[A-Z0-9_!#$%&'*+/=?`{|}~^-]+(?:\\.[A-Z0-9_!#$%&'*+/=?`{|}~^-]+↵\n" +
				")*@[A-Z0-9-]+(?:\\.[A-Z0-9-]+)*$", Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher(emailAdressen);
		return matcher.find();
	}
}
Posted by: Guest on October-30-2021
-1

("\\s","")regex java

x.replaceAll("\\s+", "");
Posted by: Guest on December-01-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language