Showing posts with label Regular Expressions. Show all posts
Showing posts with label Regular Expressions. Show all posts

Thursday, March 17, 2016

Monday, May 6, 2013

Guid like strings in SQL

we were having an issue that there was a table that had all string values, guids and non guids, and a join on a guid table was failing so we did this


      select * into #blah
  from
  blah WITH (NOLOCK)
       where string_val LIKE REPLACE('00000000-0000-0000-0000-000000000000', '0', '[0-9a-fA-F]')

Monday, April 29, 2013

TextFieldParser reads line feeds as the end of a line

I did this to get rid of lf when they weren't line feeds with carriage returns

originalFile = System.Text.Encoding.UTF8.GetBytes(Regex.Replace(Encoding.UTF8.GetString(originalFile), "[^\r]\n", "")); 

Monday, November 5, 2012

Basic date Regular Expressions



  1. "dd/mm/yyyy","(3[01]|[12][0-9]|0[1-9])/(0[1-9]|1[012])/[1-2][0-9][0-9][0-9]"
  2. "dd-mmm-yy","(3[01]|[12][0-9]|0[1-9])[-/][a-zA-Z][a-zA-Z][a-zA-Z][-/][1-2][0-9][0-9][0-9]"
  3. "MM/dd/yyyy","(0[1-9]|1[012])/(3[01]|[12][0-9]|0[1-9])/[1-2][0-9][0-9][0-9]"
  4. "yyyy-mm-dd","[1-2][0-9][0-9][0-9][-/](0[1-9]|1[012])[-/](3[01]|[12][0-9]|0[1-9])"  
  5. "yyyy/mm/dd","[1-2][0-9][0-9][0-9]/(0[1-9]|1[012])/(3[01]|[12][0-9]|0[1-9])" 
I cheated on MMM , I know
 

Tuesday, October 16, 2012

simple c# function for stripping non-numeric


  public static string stripNonNumeric(string str)
            {
                Regex digitsOnly = new Regex(@"[^\d]");
                return digitsOnly.Replace(str, "");
            }

Thursday, June 14, 2012

Function to clean string for folder creation


public static string stripIllegal(string str)
       {
           string regex = String.Format("[{0}]", Regex.Escape(new string(Path.GetInvalidFileNameChars())));
      return Regex.Replace(str,regex,"-");
       }

in this case I exchange invalid char with -