Learn how to a build a cloud-first strategyRegister Now

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

Regex Questions

I'm currently using the code below to extract data.  I want to change the code to perform the same function except I need to exact data based on and IP address or a domain name. For example 61.1.1.1 or yahoo.com.  I don't need to have the application do both.  I just want to replace/modify this line when I need to change the search criteria.

        Dim re As New Regex("^.*?Not\sin\sDatabase.*?$", RegexOptions.Multiline)

'working code below

Imports System.Text.RegularExpressions
Imports System.IO

        Dim re As New Regex("^.*?Not\sin\sDatabase.*?$", RegexOptions.Multiline)
        Dim sr As New StreamReader("C:\resource\input.txt")
        Dim input As String = sr.ReadToEnd()
        sr.Close()
        Dim mc As MatchCollection
        Dim sw As New StreamWriter("C:\resource\results.txt")

        mc = re.Matches(input)
        For Each m As Match In mc
            sw.Write(m.Value)
        Next
        sw.Close()

Thank you in advance for your time and expertise,
Gr8life
0
gr8life
Asked:
gr8life
2 Solutions
 
ZeonFlashCommented:
From regexlib.com:  (you can test it here http://regexlib.com/RETester.aspx?regexp_id=1121 )

^((([hH][tT][tT][pP][sS]?|[fF][tT][pP])\:\/\/)?([\w\.\-]+(\:[\w\.\&%\$\-]+)*@)?((([^\s\(\)\<\>\\\"\.\[\]\,@;:]+)(\.[^\s\(\)\<\>\\\"\.\[\]\,@;:]+)*(\.[a-zA-Z]{2,4}))|((([01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}([01]?\d{1,2}|2[0-4]\d|25[0-5])))(\b\:(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]\d{4}|[1-9]\d{0,3}|0)\b)?((\/[^\/][\w\.\,\?\'\\\/\+&%\$#\=~_\-@]*)*[^\.\,\?\"\'\(\)\[\]!;<>{}\s\x7F-\xFF])?)$

0
 
Shiju SasidharanCommented:
Ok try this pattern
       
        Dim re As New Regex("[\w\-]+(\.[\w\-]+)+", RegexOptions.Multiline)
0
 
gr8lifeAuthor Commented:
Thank you very much for all your expertise and time,
Gr8life
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.

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