Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
03-23-2011, 01:13 AM
|
#1
|
|
Senior Member
Registered: Sep 2009
Location: Washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 2,136
Rep: 
|
Regular expression help
I need a regular expression that would match:
but not match
|
|
|
|
03-23-2011, 03:19 AM
|
#2
|
|
Senior Member
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,007
Rep:
|
grep "^[-0-9][0-9]*$"
Last edited by Disillusionist; 03-23-2011 at 03:19 AM.
Reason: Forgot the *
|
|
|
|
03-25-2011, 06:18 AM
|
#3
|
|
Senior Member
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,333
Rep:
|
Hya
How about ?
Code:
grep -e '-5\|-39\|9\|17'
Happy Penguins??
|
|
|
|
03-27-2011, 07:13 AM
|
#4
|
|
Senior Member
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,007
Rep:
|
I think the requirement was to match any integer number (plus or minus)
I believe the examples were just that, examples or sample data.
|
|
|
|
03-27-2011, 07:23 AM
|
#5
|
|
Member
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 697
Rep:
|
Quote:
Originally Posted by kaz2100
How about ?
Code:
grep -e '-5\|-39\|9\|17'
Happy Penguins??
|
Quite happy after a good laugh.
I like that you found a humorous way to show that we didn't
have a good definition of the problem.
|
|
|
|
03-27-2011, 07:29 AM
|
#6
|
|
Member
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 697
Rep:
|
Smeezekitty, will Disallusionist's solution work for you?
You don't mention what program you are using or in what
context. A regex that works in grep might give different
results when used in egrep or sed.
|
|
|
|
03-27-2011, 08:17 AM
|
#7
|
|
Member
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900
Rep:
|
Disillusionist's expression would also match "-" on its own, which might not be appropriate.
I would use
or
for grep's simple regular expressions. Most regex implementations should support an expression that simple.
|
|
|
|
03-27-2011, 07:57 PM
|
#8
|
|
Member
Registered: Apr 2010
Posts: 217
Rep:
|
I see that you are just checking for positive or negative numbers? In that case, use < or > operator eg >0 , or <0. No need to use regular expression.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:02 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|