Regex : remaniées et plus simple à utiliser

This commit is contained in:
Maximilien LEDOUX 2022-03-15 10:54:31 +01:00
parent 52ee6194b9
commit 6f04606c69
2 changed files with 43 additions and 17 deletions

View File

@ -0,0 +1,25 @@
package lightcontainer.protocol;
public class StandardizedDefinitions {
//Parties de regex non-utilisées en dehors de cette classe
private final static String DIGIT = "[\\x30-\\x39]";
private final static String VISIBLECHAR = "[\\x20-\\xFF]";
private final static String PASSCHAR = "[\\x20-\\xFF]";
private final static String BINARY = "[\\x00-\\xFF]";
private final static String LETTER = "[\\x41-\\x5A\\x61-\\x7A]";
private final static String DIGIT_LETTER = DIGIT + "|" + LETTER;
//Parties de regex pouvant être utilisées en dehors de cette classe
public final static String PORT = "(6553[\\x30-\\x35])|(655[\\x30-\\x32][\\x30-\\x39])|(65[\\x30-\\x34][\\x30-\\x32]{2})|(6[\\x30-\\x34][\\x30-\\x39]{3})|([\\x31-\\x35][\\x30-\\x39]{4})|([\\x30-\\x35]{0,5})|([\\x30-\\x39]{1,4})";
public final static String SIZE = DIGIT + "{1,10}";
public final static String LINE = "\\x0D\\x0A";
public final static String PASSWORD = PASSCHAR + "{5,50}";
public final static String BL = "\\x20";
public final static String FILENAME = PASSCHAR + "{1,20}";
public final static String DOMAIN = DIGIT_LETTER + "{5,20}[.]";
public final static String HASH_FILENAME = DIGIT_LETTER + "{50,200}";
public final static String HASH_FILECONTENT = DIGIT_LETTER + "{50,200}";
public final static String FILE_INFO = HASH_FILENAME + BL + SIZE + BL + HASH_FILECONTENT;
public final static String LOGIN = DIGIT_LETTER + "{5,20}";
}

View File

@ -1,22 +1,23 @@
//Standardized definitions //Standardized definitions
digit = [0-9] digit = [\x30-\x39] //Unicode
port = (6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4}) port = (6553[\x30-\x35])|(655[\x30-\x32][\x30-\x39])|(65[\x30-\x34][\x30-\x32]{2})|(6[\x30-\x34][\x30-\x39]{3})|([\x31-\x35][\x30-\x39]{4})|([\x30-\x35]{0,5})|([\x30-\x39]{1,4})
size = [0-9]{1,10} size = [\x30-\x39]{1,10}
line = \r\n line = \x0D\x0A
visiblechar = \p{Print} visiblechar = [\x20-\xFF]
passchar = [^ !] passchar = [\x22-\xFF]
binary = . binary = [\x00-\xFF]
password = [^ !]{5,50} password = [\x22-\xFF]{5,50}
bl = //espace bl = \x20 //espace
letter = [A-Za-z] letter = [\x41-\x5A\x61-\x7A]
digit_letter = [A-Za-z0-9] digit_letter = [\x30-\x39]|[\x41-\x5A\x61-\x7A]
filename = [^ !]{1,20} filename = [\x22-\xFF]{1,20}
domain = [A-Za-z0-9.]{5,20} domain = [\x30-\x39\x41-\x5A\x61-\x7A]{5,20}[.] //Le point est obligatoire
hash_filename = [A-Za-z0-9.]{50,200} hash_filename = [\x30-\x39\x41-\x5A\x61-\x7A]{50,200}
hash_filecontent = [A-Za-z0-9.]{50,200} hash_filecontent = [\x30-\x39\x41-\x5A\x61-\x7A]{50,200}
file_info = [A-Za-z0-9.]{50,200} [0-9]{1,10} [A-Za-z0-9.]{50,200} file_info = [\x30-\x39\x41-\x5A\x61-\x7A]{50,200}\x20[\x30-\x39]{1,10}\x20[\x30-\x39\x41-\x5A\x61-\x7A]{50,200}
login = [A-Za-z0-9]{2,20} login = [\x30-\x39\x41-\x5A\x61-\x7A]{5,20}
//OBSOLETE
//StorBackEnd to FileFrontEnd //StorBackEnd to FileFrontEnd
sbe_hello = ^HELLO ([A-Za-z0-9.]{5,20}) ([\d]{0,5})\r\n$ //TODO \r\n -> à tester pour voir si déjà dans le flux ou doit être construit sbe_hello = ^HELLO ([A-Za-z0-9.]{5,20}) ([\d]{0,5})\r\n$ //TODO \r\n -> à tester pour voir si déjà dans le flux ou doit être construit