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!

Looking for standard lines inside file using REGEX

Status
Not open for further replies.

viadisky

Technical User
Jun 19, 2003
110
0
0
GB
Hi,

I need the help of all regex gurus out there.

Listed below are standard lines I need to check inside a file. A file should be okay if all these lines can be found and in the right order.

ip name-server 4.3.2.1
ip name-server 3.2.3.2
ip name-server 1.1.1.1

I created a very basic REGEX to do this:

^ip name-server 4\.3\.2\.1$
^ip name-server 3\.2\.3\.2$
^ip name-server 1\.1\.1\.1$

If additional "ip name-server <IP Address>" will be placed on top or below the standard lines, the REGEX I created won't be able to see these lines.

Can anybody suggest an easy way how to modify my REGEX?

Regards
viadisky
 
Try this
Code:
^ip name-server \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Hi Spookie,

Thanks for the suggestion you provided :)
But this REGEX matched the file with these lines:

ip name-server 172.21.204.33
ip name-server 172.21.204.34
ip name-server 1.1.1.12

That's why I had to type the exact IP Addresses to have 100% match.

Regards
vaidisky
 
If you are matching exact lines why would you use a regexp?

Why not just look for those specific lines..
 
Hi travs69,

Thanks for your help.
Can you please give basic example how to use regexp?

Regards
Maria
 
is this school/class work?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top