Solved

Regex - check for order numbers starting with alpha numeric

Posted on 2011-09-28
4
277 Views
Last Modified: 2012-05-12
I have order numbers like this : WSUS00016-5 OR WSUS00016

(with and without a dash)

I need a regex to check for both... order numbers that start with alpha and have a dash and those that start with alpha and no dash...

I've tried these : ^a-zA-Z0-9 _]{1,255}
                          ^([A-Za-z]|[0-9]|_)+$
                          /^\w+$/
0
Comment
Question by:Camillia
  • 3
4 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 500 total points
ID: 36717772
[A-Za-z]{4}\d{5}(\-[0-9])?
0
 
LVL 10

Expert Comment

by:ienaxxx
ID: 36717782
you missed the number of occurrences.

try this:

^([a-zA-Z\-0-9]*)$
0
 
LVL 10

Expert Comment

by:ienaxxx
ID: 36717808
...or, if you're trying to isolate the numeric part in a separate match:

^([a-zA-Z]*)([0-9\-]*)$

This is because you defined a class of chars and not the number of chars (inside the parentheses)
Doing this will expect to find ONE char of that class.

HTH
Bye.
0
 
LVL 10

Expert Comment

by:ienaxxx
ID: 36717841
* is telling the class can be repeated 0 or more times.
+ would tell (at least one)
{1,3} would tell from one to three

and so on.
but you should specify that near the class definition "[ ]" markers, not outside the match definition "( )" markers.

if you want to match ONLY the order number that are composed by an alpha part of at least 4 chars and a num part of at least 4 that MAY contain a dash, you should search for:

^([a-zA-Z]{4,})([0-9\-]{4,})$

HTH
Bye!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now