Exemplo n.º 1
0
  ///<summary>The entry point for the application.</summary>
  ///<param name="argv">A list of command line arguments</param>
  public static void Main
  (
   String[] argv
  )
  {
   Boolean                           booleanParseCommandLineArguments          =  false;
   string                            exceptionMessage                          =  null;     
   UtilityRegularExpressionArgument  utilityRegularExpressionArgument          =  null;
   
   bool                              isMatch                                   =  false;
   Match                             match                                     =  null;
   MatchCollection                   matchCollection                           =  null;
   RegexOptions                      regexOptions                              =  new RegexOptions();
   string                            replace                                   =  null;
   string[]                          split                                    =  null;   
   
   utilityRegularExpressionArgument                =  new UtilityRegularExpressionArgument();
   
   booleanParseCommandLineArguments =  UtilityParseCommandLineArgument.ParseCommandLineArguments
   ( 
    argv, 
    utilityRegularExpressionArgument
   );

   if ( booleanParseCommandLineArguments == false )
   {
    // error encountered in arguments. Display usage message
    System.Console.Write
    (
     UtilityParseCommandLineArgument.CommandLineArgumentsUsage( typeof ( UtilityRegularExpressionArgument ) )
    );
    return;
   }//if ( booleanParseCommandLineArguments  == false )
   
   RegularExpressionRegex
   (
    ref utilityRegularExpressionArgument,
    ref regexOptions,
    ref exceptionMessage,
    ref isMatch,
    ref match,
    ref matchCollection,
    ref replace,
    ref split
   );//RegularExpressionRegex
    
  }//static void Main( String[] argv ) 
Exemplo n.º 2
0
  }//public static void RegexOptionsSet()

  ///<summary>RegularExpressionRegex</summary>
  public static void RegularExpressionRegex
  (
   ref   UtilityRegularExpressionArgument  utilityRegularExpressionArgument,
   ref   RegexOptions                      regexOptions,
   ref   string                            exceptionMessage,
   ref   bool                              isMatch,
   ref   Match                             match,
   ref   MatchCollection                   matchCollection,
   ref   string                            replace,
   ref   string[]                          split   
  )
  {
   
   HttpContext          httpContext               = HttpContext.Current;

   try
   {

    RegexOptionsSet
    (
     ref utilityRegularExpressionArgument,
     ref regexOptions,
     ref exceptionMessage
    );//RegexOptionsSet()

    isMatch = Regex.IsMatch
    (
     utilityRegularExpressionArgument.regularExpressionInput,
     utilityRegularExpressionArgument.regularExpressionPattern,
     regexOptions
    );

    match = Regex.Match
    (
     utilityRegularExpressionArgument.regularExpressionInput,
     utilityRegularExpressionArgument.regularExpressionPattern,
     regexOptions
    );

    matchCollection = Regex.Matches
    (
     utilityRegularExpressionArgument.regularExpressionInput,
     utilityRegularExpressionArgument.regularExpressionPattern,
     regexOptions
    );

    if ( utilityRegularExpressionArgument.regularExpressionReplace )
    {
     replace = Regex.Replace
     (
      utilityRegularExpressionArgument.regularExpressionInput,
      utilityRegularExpressionArgument.regularExpressionPattern,
      utilityRegularExpressionArgument.regularExpressionReplacement,
      regexOptions
     );
    }//if ( utilityRegularExpressionArgument.regularExpressionReplace )

    split = Regex.Split
    (
     utilityRegularExpressionArgument.regularExpressionInput,
     utilityRegularExpressionArgument.regularExpressionPattern,
     regexOptions
    );

   }//try
   catch( Exception exception )
   {
    exceptionMessage = "Exception: " + exception.Message;   	
   }//catch( Expression expression )   	

   if ( exceptionMessage != null )
   {
    if ( httpContext == null )
    {
     System.Console.WriteLine( exceptionMessage );
    }//if ( httpContext == null )
    else
    {
     //httpContext.Response.Write( exceptionMessage );
    }//else 
   }//if ( exceptionMessage != null )

   if ( httpContext == null )
   {

    if ( utilityRegularExpressionArgument.regularExpressionIsMatch )
    {
     System.Console.WriteLine("IsMatch: {0}", isMatch);
    }//if ( utilityRegularExpressionArgument.regularExpressionIsMatch )   	

    if ( utilityRegularExpressionArgument.regularExpressionMatch )
    {
     System.Console.WriteLine("Match: {0}", match);
    }//if ( utilityRegularExpressionArgument.regularExpressionMatch )   	

    if ( utilityRegularExpressionArgument.regularExpressionMatches && matchCollection != null )
    {
     for( int matchIndex = 0; matchIndex < matchCollection.Count; ++matchIndex )
     {
      System.Console.WriteLine("Match[{0}]: {1}", matchIndex, matchCollection[matchIndex]);
     }//for( int matchIndex = 0; matchIndex < matchCollection.Count; ++matchIndex )
    }//if ( utilityRegularExpressionArgument.regularExpressionMatches )

    if ( utilityRegularExpressionArgument.regularExpressionReplace )
    {
     System.Console.WriteLine("Replace: {0}", replace);
    }//if ( utilityRegularExpressionArgument.regularExpressionReplace )

    if ( utilityRegularExpressionArgument.regularExpressionSplit && split != null )
    {
     for( int splitIndex = 0; splitIndex < split.Length; ++splitIndex )
     {
      System.Console.WriteLine("Split[{0}]: {1}", splitIndex, split[splitIndex]);
     }//for( int splitIndex = 0; splitIndex < split.Count; ++splitIndex )
    }//if ( utilityRegularExpressionArgument.regularExpressionSplit )

   }//if ( httpContext == null )
   
  }//public static bool RegularExpressionRegex()
Exemplo n.º 3
0
  }//static void Main( String[] argv ) 

  ///<summary>RegexOptionsSet</summary>
  public static void RegexOptionsSet
  (
   ref UtilityRegularExpressionArgument  utilityRegularExpressionArgument,
   ref RegexOptions                      regexOptions,
   ref string                            exceptionMessage
  )
  {
   
   HttpContext  httpContext = HttpContext.Current;
   
   regexOptions = new RegexOptions();
   
   try
   {
    
    regexOptions = new RegexOptions();
    
   	if ( utilityRegularExpressionArgument.regexOptionsCompiled ) 
   	{
   	 regexOptions |= RegexOptions.Compiled;
   	}//if ( utilityRegularExpressionArgument.regexOptionsCompiled ) 

   	if ( utilityRegularExpressionArgument.regexOptionsCultureInvariant ) 
   	{
   	 regexOptions |= RegexOptions.CultureInvariant;
   	}//if ( utilityRegularExpressionArgument.regexOptionsCultureInvariant ) 

   	if ( utilityRegularExpressionArgument.regexOptionsECMAScript ) 
   	{
   	 regexOptions |= RegexOptions.ECMAScript;
   	}//if ( utilityRegularExpressionArgument.regexOptionsECMAScript ) 

   	if ( utilityRegularExpressionArgument.regexOptionsExplicitCapture ) 
   	{
   	 regexOptions |= RegexOptions.ExplicitCapture;
   	}//if ( utilityRegularExpressionArgument.regexOptionsExplicitCapture ) 

   	if ( utilityRegularExpressionArgument.regexOptionsIgnoreCase ) 
   	{
   	 regexOptions |= RegexOptions.IgnoreCase;
   	}//if ( utilityRegularExpressionArgument.regexOptionsIgnoreCase ) 

   	if ( utilityRegularExpressionArgument.regexOptionsIgnorePatternWhitespace ) 
   	{
   	 regexOptions |= RegexOptions.IgnorePatternWhitespace;
   	}//if ( utilityRegularExpressionArgument.regexOptionsIgnorePatternWhitespace ) 

   	if ( utilityRegularExpressionArgument.regexOptionsMultiline ) 
   	{
   	 regexOptions |= RegexOptions.Multiline;
   	}//if ( utilityRegularExpressionArgument.regexOptionsMultiline ) 

   	if ( utilityRegularExpressionArgument.regexOptionsNone ) 
   	{
   	 regexOptions |= RegexOptions.None;
   	}//if ( utilityRegularExpressionArgument.regexOptionsNone ) 

   	if ( utilityRegularExpressionArgument.regexOptionsRightToLeft ) 
   	{
   	 regexOptions |= RegexOptions.RightToLeft;
   	}//if ( utilityRegularExpressionArgument.regexOptionsRightToLeft ) 
   	
   	if ( utilityRegularExpressionArgument.regexOptionsSingleline ) 
   	{
   	 regexOptions |= RegexOptions.Singleline;
   	}//if ( utilityRegularExpressionArgument.regexOptionsSingleline ) 

   }//try
   catch( Exception exception )
   {
    exceptionMessage = "Exception: " + exception.Message;   	
   }//catch( Expression expression )
   finally
   {
    if ( httpContext == null )
    {
     System.Console.WriteLine( "RegexOptions: {0}", regexOptions );
    }//if ( httpContext == null )
   }//finally   	

   if ( exceptionMessage != null )
   {
    if ( httpContext == null )
    {
     System.Console.WriteLine( exceptionMessage );
    }//if ( httpContext == null )
    else
    {
     //httpContext.Response.Write( exceptionMessage );
    }//else 
   }//if ( exceptionMessage != null )

  }//public static void RegexOptionsSet()