[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

RegEx simple

Posted on 2011-04-27
14
Medium Priority
?
386 Views
Last Modified: 2012-05-11
Hey

I'm looking for the RegEx for the following:

All numbers from 0-10
All numbers from 0x-10x (where x is the letters a-z - and only one letter)

Thanks in advance

Mike (Using PowerShell v2)
0
Comment
Question by:mikeydk
  • 5
  • 5
  • 2
  • +1
14 Comments
 
LVL 8

Expert Comment

by:point_pleasant
ID: 35477600
All numbers from 0-10
\d
All numbers from 0x-10x (where x is the letters a-z - and only one letter
\d[a-z]
0
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 35477701
In case you need to combine them:

\d[a-z]?

where \d is digits, [a-z] is any lowercase letter, and ? is 0 or 1 occurances.
0
 
LVL 1

Author Comment

by:mikeydk
ID: 35477725
I would like to use one Regex...

All numbers from 0-10
\d (gives match all numbers, not only 0-10)
All numbers from 0x-10x (where x is the letters a-z - and only one letter
\d[a-z](gives match for ex. 9aaa)
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 8

Expert Comment

by:point_pleasant
ID: 35477927
ok try

\b[0-10][a-z]?\b

0
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 35477953
\[0-9]{1}|[0-9]{1}[a-z]{1}



0
 
LVL 1

Author Comment

by:mikeydk
ID: 35478014
developedtester>

10 does not match (should be OK)
12a match (should not be OK)
0
 
LVL 1

Author Comment

by:mikeydk
ID: 35478020
point_pleasant> I'm unable to make this work?
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 35478033
Remember that \d cannot match "10" because that'd be two digit characters, not one.

You could do this:

\d0?

But it'll match 0 to 9, then 00, 10, 20, etc.

You could use Or to get it to match 0 - 9 or 10:

\d|10

Then the character on the end of each:

(\d|10)[a-z]

Finally, position in the string is important with Match, because if you have this:

0001a

You'll get a match too. If you want to match at the beginning of the string, tell it:

^(\d|10)[a-z]

Test script:
1..20 | ForEach-Object { "$($_)a : " + ("$($_)a" -Match '^(\d|10)[a-z]') }

Open in new window

HTH

Chris
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 35478067
One more, depending on what you're matching against, you may want to tell it about the end of line as well.

^(\d|10)[a-z]$

Then you'll match this:

1a

But not these:

1aa
1a1
10a1

The tweaking can go on, but context is important.

Chris
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 2000 total points
ID: 35478123
heh one more modification. You can make the letter on the end optional. Doing so will make it match:

0 - 9
10
0a - 9z
10a - 10z

Version 3:

^(\d|10)[a-z]?$

Chris
0
 
LVL 1

Author Comment

by:mikeydk
ID: 35478146
Chris-Dent>

Thanks.. ;)

Thinks this will work: ^(\d|10)[a-z]$|^(\d|10)$
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 35478153
Yes, but see version 3 for a better optional letter :)

Chris
0
 
LVL 1

Author Comment

by:mikeydk
ID: 35478172
Yes ;) Thanks again :)
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 35478186
You're welcome :)

Chris
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question