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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:25:02+00:00 2026-06-14T12:25:02+00:00

Is there any way to parse a Complex RegEx pattern(containing several named groups as

  • 0

Is there any way to parse a Complex RegEx pattern(containing several named groups as well as several numbered groups and non-capturing groups) and report about each groupname or groupnumber along with pattern text.

Suppose, I do have a RegEx pattern like this:

  (?im)(?<x>\b[a-s03]+\b)(?-i)(?<a>\p{L}+?,(?<b>.+?:(?<c>.+?;(?<d>.+?(?:\d|sample-text|(\k'x'|sos30))))))

And I like to extract:=

  Named groups:
  x==>(?<x>\b[a-s03]+\b)
  a==>(?<a>\p{L}+?,(?<b>.+?:(?<c>.+?;(?<d>.+?(?:\d|sample-text|(\k'x'|sos30))))))
  b==>(?<b>.+?:(?<c>.+?;(?<d>.+?(?:\d|sample-text|(\k'x'|sos30)))))
  c==>(?<c>.+?;(?<d>.+?(?:\d|sample-text|(\k'x'|sos30))))
  d==>(?<d>.+?(?:\d|sample-text|(\k'x'|sos30)))

  Numbered groups:
  1==>(\k'x'|sos30)

  Non-capturing-groups:
  1st==>(?:\d|sample-text|(\k'x'|sos30))

Purpose of this Requirement:

I do have a large database of complex RegEx patterns. The previous programmar worked on this did not use any comment [(?#...)] while preparing these complex patterns, moreover no linebreaks exists within those patterns. I have to modify those patterns some cases and also have to use comment within those patterns. Now it is something like searching a needle in the haystakes. I simply could not use RegEx for this purpose. So, I inclined to use a parser for this case.

What I tried:

I tried GetGroupNames and GetGroupNumbers collection for that purpose. I could extract only the Names/Numbers of the groups, but not the corresponding textual patterns.

I am looking for a Non-RegEx solution/some hints.

  • 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-14T12:25:04+00:00Added an answer on June 14, 2026 at 12:25 pm

    How about this, for this:

    (?im)(?<x>\b[a-s03]+\b)(?-i)(?<a>\p{L}+?,(?<b>.+?:(?'c'.+?;(.+?(?:\d|sample-text|(\k'x'|sos30))))))
    

    This, as the Output:

    (0)<0>:     (?im)(?<x>\b[a-s03]+\b)(?-i)(?<a>\p{L}+?,(?<b>.+?:(?'c'.+?;(.+?(?:\d|sample-text|(\k'x'|sos30))))))
    (1)<x>:     \b[a-s03]+\b
    (2)<a>:     \p{L}+?,(?<b>.+?:(?'c'.+?;(.+?(?:\d|sample-text|(\k'x'|sos30))))
    (3)<b>:     .+?:(?'c'.+?;(.+?(?:\d|sample-text|(\k'x'|sos30)))
    (4)<c>:     .+?;(.+?(?:\d|sample-text|(\k'x'|sos30))
    (5)<5>:     .+?(?:\d|sample-text|(\k'x'|sos30)
    (6)<6>:     \k'x'|sos30
    

    This is the code:

    Imports System.Collections.Specialized
    Module Module1
    Public DictGroups As New OrderedDictionary
    Public DictTrackers As New Dictionary(Of Integer, Boolean)
    Public intGroups As Integer = 0
    Public CommandGroup As Boolean = False
    Sub Main()
        Dim regexToEval As String = "(?im)(?<x>\b[a-s03]+\b)(?-i)(?<a>\p{L}+?,(?<b>.+?:(?'c'.+?;(.+?(?:\d|sample-text|(\k'x'|sos30))))))"
        Dim curChar As String = ""
        DictGroups.Add(0, "(0)<0>: " & vbTab)
        DictTrackers.Add(0, True)
        For i = 1 To regexToEval.Length
            Dim iChar As String = regexToEval.Substring(i - 1, 1)
            If curChar <> "\" AndAlso iChar = ")" Then EndGroup()
            AddStrToTrackers(iChar)
            If curChar = "\" OrElse iChar <> "(" OrElse regexToEval.Length < i + 2 Then curChar = iChar : Continue For
            If regexToEval.Substring(i, 1) = "?" Then
                i += 1 : AddStrToTrackers("?")
                If regexToEval.Substring(i, 1) = ":" Then i += 1 : AddStrToTrackers(":") : curChar = ":" : Continue For
                Dim NameLength As Integer = 0
                If regexToEval.Substring(i, 1) = "<" Or regexToEval.Substring(i, 1) = "'" Then
                    i += 1 : AddStrToTrackers(regexToEval.Substring(i - 1, 1))
                    i += 1
                    For x = i To regexToEval.Length
                        If regexToEval.Substring(x - 1, 1) = ">" Or regexToEval.Substring(x - 1, 1) = "'" Then
                            NameLength = x - i
                            Exit For
                        End If
                    Next
                Else
                    CommandGroup = True
                    Continue For
                End If
                If NameLength > 0 Then
                    Dim GroupName As String = regexToEval.Substring(i - 1, NameLength)
                    i += NameLength : curChar = regexToEval.Substring(i - 1, 1) : AddStrToTrackers(GroupName & curChar)
                    intGroups += 1
                    DictGroups.Add(intGroups, "(" & DictGroups.Count & ")<" & GroupName & ">: " & vbTab)
                    DictTrackers.Add(intGroups, True)
                    Continue For
                End If
            End If
            curChar = iChar
            intGroups += 1
            DictGroups.Add(intGroups, "(" & DictGroups.Count & ")<" & intGroups.ToString & ">: " & vbTab)
            DictTrackers.Add(intGroups, True)
        Next
        Dim Output As String = MakeOutput()
    End Sub
    
    Private Function MakeOutput() As String
        Dim retString As String = String.Empty
        For i = 0 To DictGroups.Count - 1
            retString &= DictGroups(i) & vbCrLf
        Next
        Return retString
    End Function
    
    Public Sub EndGroup()
        If CommandGroup Then
            CommandGroup = False
            Exit Sub
        End If
        Dim HighestNum As Integer = 0
        For Each item In DictTrackers
            If Not item.Value Then Continue For
            If item.Key > HighestNum Then HighestNum = item.Key
        Next
        If HighestNum <> 0 Then DictTrackers(HighestNum) = False
    End Sub
    
    Public Sub AddStrToTrackers(ByVal addString As String)
        For Each item In DictTrackers
            If item.Value Then DictGroups(item.Key) &= addString
        Next
    End Sub
    End Module
    

    The only difference is that I’m not capturing either Non-Capture groups, nor function groups. Of course, this is just quick code I made in like 10 minutes. But it’s a start if you want it. I use the OrderedDictionary as Keys for Group-Numbers. You could change that structure if you wanted to also include non-capture groups and function groups in the output.

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

Sidebar

Related Questions

Is there any way to parse an Exception's ToString() output back into an Exception
I'm wondering, is there any standard way to parse such path-like string: Server[@Name='MyServerName']/Database[@Name='MyDatabaseName']/Table[@Name='MyTableName' and
Hi is there any way to parse strings into numbers? And is there any
Is there any way to parse a string in the format HH:MM into a
Is there any way to clear parser buffers before calling YYACCEPT in yacc .
Is there any way in Notepad++ (or even with another tool) to change the
Is there any way I can set a formatter on models that will convert
Is there any way to use Google's API to retrieve a user's current zipcode
Is there any way to overload the > (greater than) operator, to be able
Is there any way we can fetch X509 Public Cetrificates using c# from AD

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.