542 |
jp_milcent |
1 |
package org.tela_botanica.client.util;
|
|
|
2 |
|
|
|
3 |
public class Pattern {
|
728 |
jp_milcent |
4 |
|
|
|
5 |
public static final String url = "^(?:(?:ht|f)tp(?:s?)\\:\\/\\/|~/|/)?"+ // Protocol
|
|
|
6 |
"(?:\\w+:\\w+@)?"+ // Username:Password
|
|
|
7 |
"(?:(?:[-\\w]+\\.)+"+ // Subdomains
|
|
|
8 |
"(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))"+ // TopLevel Domains
|
|
|
9 |
"(?::[\\d]{1,5})?"+ // Port
|
|
|
10 |
"(?:(?:(?:/(?:[-\\w~!$+|.,=]|%[a-f\\d]{2})+)+|/)+|\\?|#)?"+ // Directories
|
|
|
11 |
"(?:(?:\\?(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=(?:[-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)(?:&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=(?:[-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)*)*"+ // Query
|
|
|
12 |
"(?:#(?:[-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)?$"; // Anchor
|
|
|
13 |
|
|
|
14 |
public static final String email = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*"+ // Identité
|
|
|
15 |
"@"+ // At
|
|
|
16 |
"(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";// Domaine
|
|
|
17 |
|
888 |
aurelien |
18 |
public static final String heureMinute = "^((([0-1][0-9])|(2[0-4])):(([0-5][0-9])|(60)))$";
|
885 |
aurelien |
19 |
|
542 |
jp_milcent |
20 |
/**
|
|
|
21 |
* Méthode similaire à la méthode : java.util.Pattern.quote().
|
|
|
22 |
* java.util.Pattern n'est pas implémenté par GWT.
|
744 |
jpm |
23 |
* Nous protégeons les caractères spéciaux.
|
542 |
jp_milcent |
24 |
*
|
|
|
25 |
* @link http://java.developpez.com/faq/java/?page=langage_chaine
|
744 |
jpm |
26 |
* @param chaine
|
542 |
jp_milcent |
27 |
* @return
|
|
|
28 |
*/
|
744 |
jpm |
29 |
public static String quote(String chaine) {
|
|
|
30 |
chaine.replace("\\", "\\\\");
|
|
|
31 |
|
|
|
32 |
String[] caracteresSpeciaux = {".", "$", "[", "]", "(", ")", "{", "}", "^", "?", "*", "+", "-"};
|
|
|
33 |
for (int i = 0; i < caracteresSpeciaux.length; i++) {
|
|
|
34 |
chaine = chaine.replace(caracteresSpeciaux[i], "\\"+caracteresSpeciaux[i]);
|
542 |
jp_milcent |
35 |
}
|
744 |
jpm |
36 |
return chaine;
|
542 |
jp_milcent |
37 |
}
|
|
|
38 |
}
|