The UNIX and Linux Forums
>
Top Forums
>
Shell Programming and Scripting
regex
.
User Name
Remember Me?
Password
google unix.com
Forums
Register
Forum Rules
Links
Albums
FAQ
Members List
Calendar
Search
Today's Posts
Mark Forums Read
Thread
:
regex
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
#
4
(
permalink
)
10-13-2008
otheus
Moderator ala Mode
Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,886
Refer to the man page section on "Pattern Matching", otherwise known in Shell parlance as "fileglob". The [0-9] is right, but "+" doesn't work here. To match a non-zero digit followed by more digits, you need:
Code:
shopt -s nullglob echo [1-9][0-9]*
If you can have leading zeros, but you don't want to match one with ONLY 0's, then you can do:
Code:
shopt -s nullglob echo [1-9][0-9]* [0-9]*[1-9][0-9]* [0-9]*[1-9]
This last one matches : (1) any number starting with a non-zero, AND (2) any number with a non-zero in the middle, AND (3) any number ending with a non-zero.
The shopt -s nullglob ensures that if the expression does not match, you get the empty string (instead of the pattern itself).
otheus
View Public Profile
Visit otheus's homepage!
Find all posts by otheus
Find otheus's past nominations received
Find otheus's present nominations given