score:0

Accepted answer

Your regex should be modified as

^[\p{L}•-]

To also allow whitespace at the start of the string add \s and use

^[\p{L}\s•-]

Details

  • ^ - start of string
  • [\p{L}•-] - a letter, or -
  • [\p{L}•-] - a letter, whitespace, or -

In C#, use

var reg = new Regex(@"^[\p{L}•-]");
foreach (Paragraph comment in
    wordDoc.MainDocumentPart.Document.Body.Descendants<Paragraph>()
       .Where<Paragraph>(comment => reg.IsMatch(comment.InnerText)))
{
    //print values
}

If you want to match those items containing cmt and also matching this regex, you may adjust the pattern to

var reg = new Regex(@"^(?=.*cmt)[\p{L}\s•-]", RegexOptions.Singleline);

If you need to only allow cmt at the start of the string:

var reg = new Regex(@"^(?:cmt|[\p{L}\s•-])");

score:1

You can. It would be better to use query syntax though, as described here: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/how-to-combine-linq-queries-with-regular-expressions

Example:

var queryMatchingFiles =  
            from file in fileList  
            where file.Extension == ".htm"  
            let fileText = System.IO.File.ReadAllText(file.FullName)  
            let matches = searchTerm.Matches(fileText)  
            where matches.Count > 0  
            select new  
            {  
                name = file.FullName,  
                matchedValues = from System.Text.RegularExpressions.Match match in matches  
                                select match.Value  
            };  

Your pattern is fine, just remove the $ from the end and add any character

 @"^[a-zA-Z-]+. *"

Related Articles