- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Need a regexp to match exactly 2 alpha & 4 digits ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2002 09:44 AM
11-18-2002 09:44 AM
Reading the man page 'regexp (5)' is making my brain hurt. I have tried using collating sequences but getting the exact sequence is tough.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2002 09:48 AM
11-18-2002 09:48 AM
Re: Need a regexp to match exactly 2 alpha & 4 digits in that sequence
m/[A-Z]{2}\d{4}/
Posix:
/[[:alpha:]]{2}[[:digit:]]{4}/
From perl:
l1:/u/usr/merijn 102 > perl -nle'print /[[:alpha:]]{2}[[:digit:]]{4}/?"":"not ","OK"'
aa2345
OK
a45678
not OK
abc3456
OK
AbAb42
not OK
a1
not OK
not OK
blah!2345
not OK
blah1234
OK
^[[A
not OK
blah12345
OK
if you need it `anchored', in perl that would be:
/\b[[:alpha:]]{2}\d{4}\b/
Note that above will honour locale settings in perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2002 09:59 AM
11-18-2002 09:59 AM
Re: Need a regexp to match exactly 2 alpha & 4 digits in that sequence
But this is in Extended Regular Expression form.
I belive that in not extended it would be something, like:
[a-zA-Z]\{2\}[0-9]\{4\}
Notice: NO SPACES
I hope it helped. Good luck.
Adam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2002 09:59 AM
11-18-2002 09:59 AM
Re: Need a regexp to match exactly 2 alpha & 4 digits in that sequence
[a-zA-Z][a-zA-Z][0-9][0-9][0-9][0-9]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2002 11:09 AM
11-18-2002 11:09 AM
Solution[[:alpha:]] is locale-safe. All perl shortcuts are locale-safe (\w, \d, ...)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2002 11:58 AM
11-18-2002 11:58 AM
Re: Need a regexp to match exactly 2 alpha & 4 digits in that sequence
seems to work well enough for my needs, but I noticed in the test set you ran that it also matched sequences of more than two letters and 4 numbers e.g. is said 'blah12345' was good when in fact it is outside the target pattern. Luckly this will work with the data I have...thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2002 12:00 PM
11-18-2002 12:00 PM
Re: Need a regexp to match exactly 2 alpha & 4 digits in that sequence
To enable your last requirement, try:
/[[:space:]][[:alpha:]]{2}[[:digit:]]{4}[[:space:]]/
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2002 12:16 PM
11-18-2002 12:16 PM
Re: Need a regexp to match exactly 2 alpha & 4 digits in that sequence
This covers more cases:
/(^|[[:space:]])[[:alpha:]]{2}[[:digit:]]{4}($|[[:space:]])/
Regards!
...JRF...