Forum Thread

Seeking quick RegEx (Regular Expression) help *SOLVED*

beowulf7 13,691 2,120 October 15, 2015 at 01:25 PM
Hey, I'm new to Regular Expression and I'm trying to whip up something quick so that only:
*port-channel<200-999>
would be matched. Therefore, if the following lines were presented, only the bold lines would be matched.

How would I write this in a RegEx? TIA!

name1_port-channel111
name1_port-channel250
name1_port-channel360
name2_port-channel234
name2_port-channel456
name3_port-channel1
name3_Ethernet1/1/0
name3_port-channel75
name4_port-channel987
name4_port-channel1000
name4_port-channel2345

9 Comments

1

Sign up for a Slickdeals account to remove this ad.

Joined Jul 2005
Toadally Irrelephant
7,589 Posts
1,187 Reputation
#2
*port-channel[2-9][0-9][0-9]$
Reply Helpful Comment? 0 0
Quote from serra View Post :
stoopid serra.
Quote from slickdeals View Post :
How did I end up here...
Joined Sep 2003
Worlds Most Modest Man
13,691 Posts
2,120 Reputation
Original Poster
#3
Quote from VorlonFrog View Post :
*port-channel[2-9][0-9][0-9]$
Thanks, I tried that in:
http://www.regexr.com/

But it's giving me an error as an invalid expression. It doesn't like that asterisk hanging out by itself. Confused
Reply Helpful Comment? 0 0
Joined Feb 2004
L10: Grand Master
6,950 Posts
944 Reputation
#4
\S*port-channel[2-9][0-9][0-9]$
Reply Helpful Comment? 1 0
Marshall: Have the rest of you guys figured out by now that mmathis is the smartest guy on SlickDeals?
Joined Jan 2006
L10: Grand Master
11,220 Posts
1,465 Reputation
#5
There are many flavours of regex. What is your platform looking for?
Reply Helpful Comment? 0 0
Heifer whines could be human cries
Closer comes the screaming knife
Joined Sep 2003
Worlds Most Modest Man
13,691 Posts
2,120 Reputation
Original Poster
#6
Quote from mmathis View Post :
\S*port-channel[2-9][0-9][0-9]$
Perfect, that worked! Thanks! Reps to you and VFrog. nod

Quote from vivahate View Post :
There are many flavours of regex. What is your platform looking for?
I'm not sure. I was trying to construct a statement to pattern match some port-channels on our devices with our network management tool. What mmanthis wrote worked!
Reply Helpful Comment? 0 0
Last edited by beowulf7 October 15, 2015 at 02:05 PM
Joined Jul 2005
Toadally Irrelephant
7,589 Posts
1,187 Reputation
#7
Quote from beowulf7 View Post :
Perfect, that worked! Thanks! Reps to you and VFrog. nod
Thanks! Sorry I didn't get it 100% correct. Glad MMathis fixed it for you! woot
Reply Helpful Comment? 0 0
#8
There are some Android apps that allow one to construct a Regex. Come in handy.
Reply Helpful Comment? 0 0

Sign up for a Slickdeals account to remove this ad.

Joined Sep 2003
Worlds Most Modest Man
13,691 Posts
2,120 Reputation
Original Poster
#9
Quote from VorlonFrog View Post :
Thanks! Sorry I didn't get it 100% correct. Glad MMathis fixed it for you!
No prob. I originally had the "port-channel[2-9][0-9][0-9]" part but wasn't sure how to wildcard it so that the entire string gets picked up. nod
Quote from Ostracus View Post :
There are some Android apps that allow one to construct a Regex. Come in handy.
Interesting, I'll look into that the next time. Googling around for cheat sheets yielded many hits, but I wasn't able to make heads or tails of it for the wildcarding I just mentioned.
Reply Helpful Comment? 0 0
#10
Quote from beowulf7 View Post :
No prob. I originally had the "port-channel[2-9][0-9][0-9]" part but wasn't sure how to wildcard it so that the entire string gets picked up. nod
This actually depend on the mode of your regex parser. Your original regex is fine if you're searching for the regex, but if your matching the whole line against the regex it will fail.

If you really don't care what you're discarding, .* (any char repeated any number of times) is the canonical way to match anything in a regex. The one you used matches any number of non space characters before the part you were interested in.
Reply Helpful Comment? 0 0
Page 1 of 1
1
Join the Conversation
Add a Comment
 
Copyright 1999 - 2016. Slickdeals, LLC. All Rights Reserved. Copyright / Infringement Policy  •  Privacy Policy  •  Terms of Service  •  Acceptable Use Policy (Rules)  •  Interest-Based Ads
Link Copied to Clipboard