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

  • Home
  • SEARCH
  • 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 638791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:46:17+00:00 2026-05-13T20:46:17+00:00

First, a little background. I have strings that resemble the following: ((Foo.Bar.StartsWith(A)) && (Foo.Bar.EndsWith(B)))

  • 0

First, a little background. I have strings that resemble the following:

((Foo.Bar.StartsWith(“A”)) &&
(Foo.Bar.EndsWith(“B”)))

And I’m trying to reformat these to look like this:

((Foo.Any(Bar.StartsWith(“A”))) &&
(Foo.Any(Bar.EndsWith(“B”))))

Side Note: The parts following the .Bar may sometimes not include (), like .Bar == “AB” .

I’m trying to capture two groups: the Foo. and the Bar.StartsWith(“<A or B>”) . I worked out the following pattern but it drops the trailing parenthesis.

\((Foo\.)(.*?)\)

So instead of getting what I’m looking for, I’m getting:

((Foo.Any(Bar.StartsWith(“A”)) &&
(Foo.Any(Bar.EndsWith(“B”)))

Which is two parentheses short.

The problem is I need to include closing parentheses in the .*? match IF there’s also an opening parenthesis in there. I haven’t figured out how to do this, anyone know?

PS – The code is C#.NET but that shouldn’t matter unless the solution involves some obscure language-specific RegEx stuff.

  • 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-13T20:46:17+00:00Added an answer on May 13, 2026 at 8:46 pm

    Is there a reason you have to do this with regular expressions? Trying to find “matching” pairs is one of the things that regex does not do well.

    I would just do it through normal code. Do a search to find "(Foo.", then make a loop that iterates over the subsequent characters, keeping a counter for how many open/close parentheses you have passed. Increment it when you hit a ( and decrement when you hit a ). If you hit a closing parenthesis and the counter is at 0, that’s the end of the string you need to capture. Stop capturing at that point, take that string and put it inside your Any() that you’re adding. Then find the next "(Foo.".

    Does that make sense? I could probably pseudocode it if you’re not really following what I mean. Of course, this is only a valid option if you’re able to abandon regular expressions anyway.

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

Sidebar

Related Questions

First a little background: I have an Event model that has various event_type s.
First, a little background: I'm displaying a data set with 288 rows and 8
A little background first as to why I need this. I am currently creating
Background: I have extensive experience in web applications, but I have very little or
First a little intro: Last year i wrote this http://dragan.yourtree.org/code/canvas-3d-graph/ Now, i want to
First question on here so please be nice :) I know very little about
I know this question might sound a little cheesy but this is the first
OK, having tried my first TDD attempt, it's time to reflect a little and
First off, I am using Windows XP. I have multiple hard drives and it
First of all, I know how to build a Java application. But I have

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.