I'm trying to write a regex that removes all leading whitespace like this:
The following code does this, but also greedily removes multiple lines, like this:
How can I change the regex so that it removes preceding whitespace from each line, but leaves the multiple lines intact?
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace test_regex_double_line
{
class Program
{
static void Main(string[] args)
{
List<string> resources = new List<string>();
resources.Add("Jim Smith\n\t123 Main St.\n\t\tWherever, ST 99999\n\nFirst line of information.\n\nSecond line of information.");
foreach (var resource in resources)
{
var fixedResource = Regex.Replace(resource, @"^\s+", m => "", RegexOptions.Multiline);
Console.WriteLine($"{resource}\n--------------\n{fixedResource}\n===========================");
}
}
}
}