Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Regex to isolate several different words

Posted on 2010-09-11
5
Medium Priority
?
326 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 664 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 672 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 664 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

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…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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…
Introduction to Processes

688 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