Solved

Regex to isolate several different words

Posted on 2010-09-11
5
317 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
Comment Utility
Try this pattern....

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

Wayne
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 168 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Object to array 7 26
Check if number is currency 15 28
Create XML 5 30
VB.NET HttpWebRequest 12 30
This is about my first experience with programming Arduino.
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now