Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expressions 1

Status
Not open for further replies.

Niv3k

Programmer
Jul 11, 2001
350
0
0
US
I am trying to go through a string that looks like this:

Device ID: ArouterName
Entry address(es):
IP address: 1.4.2.3
Platform: cisco WS-C2924-XL, Capabilities: Trans-Bridge Switch
Interface: FastEthernet0/0, Port ID (outgoing port): FastEthernet0/1
Holdtime : 141 sec

And retrieve two submatches: IP address and Port ID (in this case, 1.4.2.3, and FE0/1). I can retrieve the IP address just fine, but I am not able to get the Port ID in the same expression. One of the expressions I am using is:
"IP address: (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})([.\n]*)Port ID \(outgoing port\): (.*)"
because I do not know how many lines are between IP address and Port ID. Any help is greatly appreciated...

Kevin
 
I'm not sure how much help I'm going to be because I don't know anything about regex's in vb. I had to do something similar, but I did it the hard way: using the instr and mid functions. It looks like you could get the position of the Port ID by using instr, then add the number of characters in 'Port ID (outgoing port): ' (25 chars). Use the resulting number and get everything from there until the next blank space (or carriage return-line feed? --> use vbCrLf, vbCr, or vbLf). Use instr again to get the position of the blank space with a starting position of the value you just computed. Then use mid from the starting position with a length that you calculate (position of blank space - start position of port id).
Wish I knew more about regex's in vb....hope this helps anyway.
Kevin
 
Yeah, that's too much work. I thought about that one, but I really would rather get it in one RegExp, because it's much faster than Instr.
 
Try the following pattern:

"IP address: (\d{1,3}\.)+(\d{1,3})|Port ID (.)+"

Obviously, you'll want to ensure that RegExp.Global is set to True to get multiple matches.
 
Okay that helped, but unfortunately the | makes it so the IP address is one match, and the Port is the second, so I just have to take that into account. But thanks!

Kevin
 
What 'function' are you using the 'RegularExpression' with? I did not find anything re "reg*" in the help. It "looks like" Grep, but ...

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Ummm, Execute? When I get a pattern, I "Execute" (method of RegExp object) it on a string... Then I iterate through the matches, and put the data into a database.
 
We're using the Microsoft VBScript Regular Expressions library. And yes, it looks like grep since grep uses regular expressions as well.
 
Is there some way to get the syntax for it to show up in VB Help?

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Thank you.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top