FormeleMethode/RegExpression.cs
/// <summary>
/// Converts a string to a regExpressionObject.
/// </summary>
/// <param name="regexString">The regex string.</param>
/// <returns></returns>
Converts a string to a regExpressionObject.
Converts a string to a regExpressionObject .
public RegExpression StringToRegExpression(RegExpression regex, string regexString)
		{
			regexString = regexString.Replace(" ", String.Empty);
			char[] seperators = { '+', '*', '|', '(', ')' };
			List<string> terminalParts = regexString.Split(seperators).ToList();
			terminalParts.RemoveAll(x => x == String.Empty);
			int terminalIndex = 0;
			int maxTerminals = terminalParts.Count();
			int i = 0;
			while (i < regexString.Length)
			{
				char currentChar = regexString[i];
				if (currentChar == '(')
				{
					int closingBracketPosition = -1;
					int bracketCount = 0;
					for (int j = i + 1; i < regexString.Length; j++)
					{
						if (regexString[j] == '(') bracketCount++;
						if (regexString[j] == ')' && bracketCount == 0)
						{
							closingBracketPosition = j;
							break;
						}
						if (regexString[j] == ')' && bracketCount != 0)
						{
							bracketCount--;
						}
					}
					string between = regexString.Substring(i + 1, closingBracketPosition - 1 - i);
					RegExpression regExpression = StringToRegExpression(new RegExpression(), between);
					if (closingBracketPosition + 1 < regexString.Length)
					{
						i = closingBracketPosition + 1;
						currentChar = regexString[i];
						if (currentChar == '+')
						{
							regExpression = regExpression.Plus();
						}
						else if (currentChar == '*')
						{
							regExpression = regExpression.Star();
						}
					}
					if (regex.terminals == "" && regex.o == Operator.ONE)
					{
						regex = regExpression;
					}
					else
					{
						regex = regex.Dot(regExpression);
					}
				}
				else if (currentChar == '+')
				{
					regex = regex.Plus();
				}
				else if (currentChar == '*')
				{
					regex = regex.Star();
				}
				else if (currentChar == '|')
				{
					regex = regex.Or(new RegExpression(terminalParts[terminalIndex].ToString()));
					terminalIndex++;
					i++;
				}
				else
				{
					if (regex.terminals == "" && regex.o == Operator.ONE)
					{
						regex.terminals = terminalParts[terminalIndex];
						int num = regex.terminals.Count();
						i += terminalParts[terminalIndex].Length - 1;
						terminalIndex++;
					}
					else
					{
					}
				}
				i++;
			}
			//	
			//			
			//		
			//		
			//	
			//			
			//			
			return regex;
		}
public RegExpression StringToRegExpression ( RegExpression regex , string regexString ) { regexString = regexString . Replace ( " " , String . Empty ) ; char [ ] seperators = { ' ' , ' ' , ' ' , ' ' , ' ' } ; List < string > terminalParts = regexString . Split ( seperators ) . ToList ( ) ; terminalParts . RemoveAll ( x => x == String . Empty ) ; int terminalIndex = 0 ; int maxTerminals = terminalParts . Count ( ) ; int i = 0 ; while ( i < regexString . Length ) { char currentChar = regexString [ i ] ; if ( currentChar == ' ' ) { int closingBracketPosition = - 1 ; int bracketCount = 0 ; for ( int j = i + 1 ; i < regexString . Length ; j ++ ) { if ( regexString [ j ] == ' ' ) bracketCount ++ ; if ( regexString [ j ] == ' ' && bracketCount == 0 ) { closingBracketPosition = j ; break ; } if ( regexString [ j ] == ' ' && bracketCount != 0 ) { bracketCount -- ; } } string between = regexString . Substring ( i + 1 , closingBracketPosition - 1 - i ) ; RegExpression regExpression = StringToRegExpression ( new RegExpression ( ) , between ) ; if ( closingBracketPosition + 1 < regexString . Length ) { i = closingBracketPosition + 1 ; currentChar = regexString [ i ] ; if ( currentChar == ' ' ) { regExpression = regExpression . Plus ( ) ; } else if ( currentChar == ' ' ) { regExpression = regExpression . Star ( ) ; } } if ( regex . terminals == " " && regex . o == Operator . ONE ) { regex = regExpression ; } else { regex = regex . Dot ( regExpression ) ; } } else if ( currentChar == ' ' ) { regex = regex . Plus ( ) ; } else if ( currentChar == ' ' ) { regex = regex . Star ( ) ; } else if ( currentChar == ' ' ) { regex = regex . Or ( new RegExpression ( terminalParts [ terminalIndex ] . ToString ( ) ) ) ; terminalIndex ++ ; i ++ ; } else { if ( regex . terminals == " " && regex . o == Operator . ONE ) { regex . terminals = terminalParts [ terminalIndex ] ; int num = regex . terminals . Count ( ) ; i += terminalParts [ terminalIndex ] . Length - 1 ; terminalIndex ++ ; } else { } } i ++ ; } return regex ; }
Converts a string to a regExpressionObject.
Converts a string to a regExpressionObject .
// Remove spaces // Seperate all terminals // For everything between ( ) // We found the matching closing bracket // Get the regex for the part between  () // Look for the part after closing bracket  // For all the operators not related to () // Skip rest of the terminal part in the loop //regex = regex.Dot(new RegExpression(currentChar.ToString())); //for (int i = 0; i < regexString.Length; i++) //{ //	char currentChar = regexString[i]; //	// For everything between ( ) //	if (currentChar == '(') //	{ //		int closingBracketPosition = -1; //		int bracketCount = 0; //		for (int j = i + 1; i < regexString.Length; j++) //		{ //			if (regexString[j] == '(') bracketCount++; //			// We found the matching closing bracket //			if (regexString[j] == ')' && bracketCount == 0) //			{ //				closingBracketPosition = j; //				break; //			} //			if (regexString[j] == ')' && bracketCount != 0) //			{ //				bracketCount--; //			} //		} //		// Get the regex for the part between  () //		string between = regexString.Substring(i + 1, closingBracketPosition - 1 - i); //		RegExpression regExpression = StringToRegExpression(new RegExpression(), between); //		// Look for the part after closing bracket  //		if (closingBracketPosition + 1 < regexString.Length) //		{ //			i = closingBracketPosition + 1; //			currentChar = regexString[i]; //			if (currentChar == '+') //			{ //				regExpression = regExpression.Plus(); //			} //			else if (currentChar == '*') //			{ //				regExpression = regExpression.Star(); //			} //		} //		if (regex.terminals == "" && regex.o == Operator.ONE) //		{ //			regex = regExpression; //		} //		else //		{ //			regex = regex.Dot(regExpression); //		} //	} //	// For all the operators not related to () //	else if (currentChar == '+') //	{ //		regex = regex.Plus(); //	} //	else if (currentChar == '*') //	{ //		regex = regex.Star(); //	} //	else if (currentChar == '|') //	{ //		regex = regex.Or(new RegExpression(terminalParts[terminalIndex].ToString())); //		terminalIndex++; //		i++; //	} //	else //	{ //		if (regex.terminals == "" && regex.o == Operator.ONE) //		{ //			regex.terminals = terminalParts[terminalIndex]; //			// Skip rest of the terminal part in the loop //			int num = regex.terminals.Count(); //			i += terminalParts[terminalIndex].Length - 1; //			terminalIndex++; //		} //		else //		{ //			//regex = regex.Dot(new RegExpression(currentChar.ToString())); //		} //	} //}
None
regex
RegExpression
regexString
string
The regex string.
The regex string .