Regular Expressions

There are 3 entries for the tag Regular Expressions

Regular Expression to extract quoted text

If you have a text enclosed with single or double quotes and optionally containing escaped quotes inside the text, the following regular expression will help you to extract the text: (['"])(?<text>.*?)(?<!\\)\1 For example, parsing text: 'Hello world'  'World\'s test' "World's test" will yield following results: Hello world World\’s test World’s test Technorati Tags: Regular Expressions

How to split SQL file by GO statement

In some situations when using scripts to create/update database in code, I had to split input SQL script file by GO statements, as SqlCommand doesn’t really understand it. But in some place, I’ve came to a strange-looking code that does exactly that but… in really weird and NOT correct way. So here we go. How NOT to write: //separator char not used in TSQL char ch = '^';   //Ed: str is the text from SQL batch file ...

Replacing passwords on application logs

Many applications write various information into log files and sometimes this information is sensitive, e.g. contains user passwords. In my case, I knew that we are logging SQL statements with stored procedures calls and one of the parameters may contain user’s password. So I have been asked to replace such passwords with something neutral. I’ve ended with following regular expression string (works only for stored procedures and alike call logs!): (?<Pre>(pass(word)?|pwd)[^=']*=[^']*'?)(?<Target>[^']+)(?<Post>'?) Technorati Tags: Regular Expressions, CSHarp, C#