Search code examples
c#regexregular-language

Regular Expression matching empty string before a character in c#


I am trying to match a string containing nothing before a character.

Consider the following lines:

'this is a valid line
  'this is also a valid line
 Any string ' this is an invalid line

I Need a regular expression that matches the first two line and does not match third line.

Basic regex tried was '.* but it matches all the three lines:

So need a regex that does not match a non empty string before '


Solution

  • perhaps try anchor at the beginning... ^\s*'.*