Solved

Regex to isolate several different words

Posted on 2010-09-11
5
320 Views
Last Modified: 2012-05-10
Could somebody help.....Tearing my hair out. I'm trying to use regular expressions to build a code analyzing programme....Dont ask why....
I would like a regular expression to get all words after the Dim statement, all words after As statement but only if not followed by a New, and all words after a New statement including the dots but excluding things in brackets....Pretty complicated....To show what I mean, I have highlighted the words I want in inverted commas from an example statement

   Dim" fs" As "System.IO.FileStream"
        Dim "r" As New "System.IO.BinaryReader"
0
Comment
Question by:sebastiz
5 Comments
 
LVL 47

Assisted Solution

by:Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs) earned 166 total points
ID: 33652982
Try this pattern....

    Dim ([a-zA-Z0-9_]+) As[ New]* ([a-zA-Z0-9_.]+)

Wayne
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 168 total points
ID: 33655847
I wonder if you'll be doing multiple declarations in the same line. This should cover either scenario:

    (?<=Dim.*?)(?:, )?([a-zA-Z_]\w*) As (?:New )?([\w.]+)

You will then have variable name in capture group 1 and type in capture group 2. The syntax you would use to get the values would be:

For Each m As Match In regex.Matches(searchtext))
    Dim v As String = m.Groups[1].Value
    Dim t As String = m.Groups[2].Value
Next
0
 
LVL 5

Assisted Solution

by:vks_vicky
vks_vicky earned 166 total points
ID: 33669857
Try this

Dim[\s]*([\"a-zA-Z0-9_]+\")[\s]*As[\s]* ([\"a-zA-Z0-9_.]+\")

and

Dim[\s]*([\"a-zA-Z0-9_]+\")[\s]*As[\s]*New[\s]*([\"a-zA-Z0-9_.]+\")
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 34049747
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question