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 8042265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:31:07+00:00 2026-06-05T04:31:07+00:00

In this code below I’d like to return this string suing regex: ‘ DataSource=xxxtransxxx;Initial

  • 0

In this code below I’d like to return this string suing regex: ‘DataSource=xxxtransxxx;Initial Catalog=Sales‘

Sales could or could not have a prefix and there could or could not be spaces in between the items in the string above. I have tried the regex in the code below but it does not work. Any advice appreciated, thanks!!

var thestring = @"'SELECT CONVERT(VARCHAR(MAX), [Measures].[EmployeeID ParameterCaption]) AS [EmployeeID]
                            ,CONVERT(VARCHAR(50),  [Measures].[Sales Rep Name ParameterCaption]) AS [EmployeeName]
                            ,CONVERT(VARCHAR(50),  [Measures].[Manager EmployeeID ParameterCaption]) AS   [ManagerEmployeeID]
                            ,CONVERT(MONEY, [MEASURES].[PrevFYYTD])AS  PrevFYYTD
                            ,CONVERT(MONEY, [MEASURES].[CurrentFYYTD] ) AS CurrentFYYTD 
                            ,CONVERT(VARCHAR(50),[MEASURES].[PCTGrowth] )+''%'' AS [PCTGrowth]
                            ,CONVERT(VARCHAR, [MEASURES].[DollarGrowth] ) AS DollarGrowth 
                            ,CONVERT(VARCHAR, [MEASURES].[HasParent] )  AS HasParent
                            ,CONVERT(VARCHAR, [MEASURES].[HasChild] ) AS HasChild 
                       FROM OPENROWSET(''MSOLAP'',''DataSource=xxxtransxxx;Initial Catalog=Sales''  , SET @MDX =     ''' WITH;";

        Regex rgx = new Regex(@"'\s*DataSource\s*=\s.*trans*(.*Sales) *'", RegexOptions.IgnoreCase);
        string result = rgx.Match(thestring).Groups[0].Value;
  • 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-06-05T04:31:09+00:00Added an answer on June 5, 2026 at 4:31 am

    You could use

    \s*DataSource\s*=[^';]+?;\s*Initial *Catalog\s*=[^;']+$
    

    code

    string resultString = null;
    try {
        resultString = Regex.Match(subjectString, @"\bDataSource\s*=[^';]+?;\s*Initial *Catalog\s*=[^;']+", RegexOptions.IgnoreCase | RegexOptions.Multiline).Value;
    } catch (ArgumentException ex) {
        // Syntax error in the regular expression
    }
    

    explanation

    @"
    (?i)          # Match the remainder of the regex with the options: case insensitive (i)
    \b            # Assert position at a word boundary
    DataSource    # Match the characters “DataSource” literally
    \s            # Match a single character that is a “whitespace character” (spaces, tabs, and line breaks)
       *             # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
    =             # Match the character “=” literally
    [^';]         # Match a single character NOT present in the list “';”
       +?            # Between one and unlimited times, as few times as possible, expanding as needed (lazy)
    ;             # Match the character “;” literally
    \s            # Match a single character that is a “whitespace character” (spaces, tabs, and line breaks)
       *             # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
    Initial       # Match the characters “Initial” literally
    \             # Match the character “ ” literally
       *             # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
    Catalog       # Match the characters “Catalog” literally
    \s            # Match a single character that is a “whitespace character” (spaces, tabs, and line breaks)
       *             # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
    =             # Match the character “=” literally
    [^;']         # Match a single character NOT present in the list “;'”
       +             # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
    "
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code below where I loop through string and compare everything char
This code below is for executing ls -l | wc -l. In the code,
This code below works in all web browsers except IE: <input type="text" name="passwordLogin" value="Password"
This code below doesn't work correctly since my MFC program is in unicode circumstance.
The code below is creating a server to communicate with clients.This code works fine
i am using this code below to dynamically capture the name of the button
I have this code below. As you can see I am passing two variables
Hi I'm using this code below to let a user draw their signature on
Just wondering about this code below... when I turn off my internet connection and
I have this code below: $insert = array(); for ($i = 1, $n =

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.