Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5988823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:00:48+00:00 2026-05-22T23:00:48+00:00

Can a LINQ expression replace all cases where regex would have previously been used?

  • 0

Can a LINQ expression replace all cases where regex would have previously been used?

In other words; does a regex exist that can not be represented by a LINQ query?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:00:49+00:00Added an answer on May 22, 2026 at 11:00 pm

    It’s probably possible to craft a LINQ expression for any given regular expression, but doing so will likely be unreasonable in many cases. Even if you eliminate things like backreferences, regular expressions can be arbitrarily complex. The beauty of regular expressions (and I find it somewhat surprising that I use the term “beauty” to describe regex) is that it’s a compact and expressive, but very narrowly focused tool for pattern matching in strings.

    LINQ, on the other hand, is a very expressive general purpose tool.

    Take a simple regular expression like (ab)+([0-9^%#@-.,]{1,5})ab[0-9]$. Can you write a LINQ expression for that? If you can, it’s going to be quite verbose–certainly much more verbose than the regex, and you’ll have to include code that gets the capture groups. Not only do you have to say if the string matches the expression, but you have to say where the match starts, how long it is, etc. I suspect it’s possible, but you’re going to write a whole lot of custom code to do it.

    I’m not a huge fan of the regex, but it does have its place. Sometimes it really is the right tool for the job. I’d jump at the chance to replace it with something better, but LINQ sure isn’t it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can SQL Server 2000 be used as the database for LINQ to SQL? Does
I have a pretty complicated Linq query that I can't seem to get into
Can LINQ to SQL query using NOT IN ? e.g., SELECT au_lname, state FROM
Can a LINQ enabled app run on a machine that only has the .NET
Can a Linq query retrieve BLOBs from a Sql Database? And how do they
How can I use Linq with Dataset.xsd files? I've looked at Linq-to-Datasets and Linq-to-XSD
Assuming you can't use LINQ for whatever reason, is it a better practice to
Everything I can find in linq for aggregation has a group by clause. How
With LINQ to SQL in a ASP.NET MVC website I can display objects (records)
How can I access dynamically properties from a generated LINQ class ? Cause I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.