public SRex(EPat cp, int?repetitionMin = null, int?repetitionMax = null, bool fromLineBeginning = false, bool endsWith = false) : this() { string pattern = (fromLineBeginning ? "^" : "") + "(" + TranslateInRegEx(cp) + ")"; string repetition = GetRepetition(repetitionMin, repetitionMax, endsWith); AddNewPattern(pattern, false, repetition); }
public SRex NotFollowedBy(EPat cp) { string nextPattern = TranslateInRegEx(cp); if (!nextPattern.StartsWith("[")) { throw new Exception("'Not' isn't suitable for: " + cp.ToString()); } nextPattern = "[^" + nextPattern.Substring(1); return(AddNewPattern(nextPattern, false, "")); }
private string TranslateInRegEx(EPat cp) { switch (cp) { case EPat.NUMBERS: return("[0-9]"); case EPat.LETTERS_UCASE: return("[A-Z]"); case EPat.LETTERS_LCASE: return("[a-z]"); //case EPat.LETTERS: // return "[A-Za-z]"; //case EPat.LETTERS_NUMS: // return "[A-Za-z0-9]"; case EPat.SPACE: return("[ ]"); case EPat.ANY_SPACE: return(@"\s"); case EPat.ANY_CHAR: return("."); case EPat.TAB: return(@"\t"); case EPat.NEWLINE: return(@"\n"); case EPat.CARRIAGE_RETURN: return(@"\r"); default: throw new Exception("Unrecognize " + cp.ToString()); } }
public SRex FollowedBy(EPat cp, int?repetitionMin = null, int?repetitionMax = null, bool endsWith = false) { string repetition = GetRepetition(repetitionMin, repetitionMax, endsWith); return(AddNewPattern(TranslateInRegEx(cp), true, repetition)); }
public SRex AndBy(EPat cp, int?repetitionMin = null, int?repetitionMax = null, bool endsWith = false) { string repetition = GetRepetition(repetitionMin, repetitionMax, endsWith); return(AddToPrevPattern(TranslateInRegEx(cp), repetition)); }