Solved

Regex to isolate several different words

Posted on 2010-09-11
5
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
Part One of the two-part Q&A series with MalwareTech.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Starting up a Project

623 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