Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Returning the ordinal position of regex matches in the original string
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Sathyaish  
View profile  
 More options May 10, 5:16 pm
From: Sathyaish <sathya...@gmail.com>
Date: Sun, 10 May 2009 14:16:01 -0700 (PDT)
Local: Sun, May 10 2009 5:16 pm
Subject: Returning the ordinal position of regex matches in the original string
For fun, I'm developing a utility that will take an input string and a
regex and will color highlight all matches of the regex in the
original string, alike the Find function in Firefox or IE 8, and some
popular browsers.

I am using C#. Does any member of the System.Text.RegularExpressions
namespace return the ordinal positions of the matches in the original
string? I also need their lengths.

Is there a way to get this information?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mkweaver  
View profile  
 More options Jun 13, 1:55 pm
From: mkweaver <mikeweaver...@gmail.com>
Date: Sat, 13 Jun 2009 10:55:06 -0700 (PDT)
Local: Sat, Jun 13 2009 1:55 pm
Subject: Re: Returning the ordinal position of regex matches in the original string
In VB.Net I'm doing this - hopefully it will point you in the right
direction:

001 Public Function GetDefuns(ByVal strFileText As String, ByRef
lspFile As LispFile) As Collection
002     '  Consider this:                  (?<!;)\(defun c:([^(]+)[^;]
+;+ *(.*)$
003     Dim objRegex As Regex = New Regex("(?<!;)\(defun ([^(]+)[^;]+;
(.*)$", RegexOptions.Multiline Or RegexOptions.IgnoreCase)
004     Dim colReturns As New Collection
005     objRegex.Matches(strFileText)
006     With objRegex
007       For Each objMatch As Match In .Matches(strFileText)
008         Dim objDefun As New Defun
009         With objDefun
010           .SourceFile = lspFile
011           .Name = objMatch.Groups.Item(1).Captures.Item(0).ToString
().Trim()
012           .ShortDescription = objMatch.Groups.Item(2).Captures.Item
(0).ToString().Trim()
013           .IsCommand = Left(.Name, 2).ToUpper = "C:"
014           .StartPoint = objMatch.Groups.Item(2).Captures.Item
(0).Index
015         End With
016         colReturns.Add(objDefun)
017

... snippage ...

121       Next
122     End With
123     Return colReturns
124   End Function

Note line 014 is getting the ordinal position of the start of the
second capture group.

On May 10, 3:16 pm, Sathyaish <sathya...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google