Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

Regex to isolate several different words

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
sebastiz
Asked:
sebastiz
3 Solutions
 
Wayne Taylor (webtubbs)Commented:
Try this pattern....

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

Wayne
0
 
käµfm³d 👽Commented:
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
 
vks_vickyCommented:
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
 
DhaestCommented:
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now