score:0
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-]+. *"
Source: stackoverflow.com
Related Articles
- Can LINQ be used to search for multiple Regex expressions in a string?
- Can LINQ be used to search for Regex expressions in a string?
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Regex in Linq (EntityFramework), String processing in database
- How to pass LinQ Expressions from F# to C# code
- LINQ search though a list of string arrays for a particular string
- LINQ Source Code Available
- How can I dynamically store expressions used for Linq Orderby?
- How to search string not in char array using LinQ
- Search string in list using linq
- Perform string search with Linq to Entities
- Why do linq search has a huge difference in efficiency when I use string and array especially for large data?
- Best option how to find last 2 digits in string with RegEx or LINQ in C#?
- creating Linq to sqlite dbml from DbLinq source code
- Stubbing Code for Test With Linq Expressions and Lambdas
- how to search string in Linq to SQL using contains
- linq to entities changing database connection string in code
- Combining regex and linq to split string in c#
- Open source LINQ search engine for website
- MVC ASP.Net LINQ syntax to search for any or part of string
- How to Convert a search string into a LINQ Query?
- Linq - Search table records contains any letter of search string
- How to compose Linq 'or' query by iterating over collection of string search parameters
- LINQ query result with string manipulation and regex
- Should LINQ Expressions be used inside foreach loop or not?
- Linq to EF Search for a string that does not start with a Letter
- How to search a list of objects for a specific string attribute using LINQ in C#
- Need LINQ query to search a list of string in a list of input values
- Using LINQ to search comma separated string
- How to do a string compare using regex and linq to sql
- LINQ-to-XML to DataGridView: Cannot edit fields -- How to fix?
- How to Convert Method Based query to Query Expression in Linq
- Futures in nHibernate Linq
- Grouping and SUM with LINQ (on conditions)
- linq to retrieve name instead of id and list in descending order
- Linq Query to update XML file if element exists not working
- How can I get all nested items from a collection?
- Get the Substrings within the List<string> collection using Linq
- linq query Take() takes precedence over Distinct()?
- Javascript (jquery) functionality similar to linq's Where()
- Read XML element from free geo location service
- How do I remove format from Linq property?
- How to solve error when getting max value in a row (EF Core Linq)?
- Error: Only parameterless constructors and initializers are supported in LINQ to Entities
- Create a String[] between the range of year
- Calling sql-specific operator/function (Full Text search) while still using ORM
- Index (zero based) must be greater than or equal to zero and less than the size of the argument list in ef 5.0 query
- LINQ query NotSupportedException OrderBy Average of TimeSpan
- LINQ and .COUNT timing out
- Paging dynamic query results