I get that [A-Z,a-z,0-9] is all upper, lower case letters and all numbers. But what to do with all the other keys on the keyboard? Right now I want the - sign, but who knows what I'll be needing another day.
Is it d+, or $, or *? Problem with these three is they seem to be too broad. Surely there's a smaller more specific option, no?
What would you do to cover this kind:
/F2BAC-HE35G-130075
[A-Z,a-z,0-9] doesnt get the first - and so stops and gives up.
4 replies to this topic
#1
Posted 21 March 2011 - 05:32 PM
|
|
|
#2
Posted 22 March 2011 - 04:44 AM
You could so something like [a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}
This will validate that string and allow any case number or any number and it expects three sets of 5 characters separated by a hyphen. Let me know if that helps. I think the commas in your example were breaking the regex.
This will validate that string and allow any case number or any number and it expects three sets of 5 characters separated by a hyphen. Let me know if that helps. I think the commas in your example were breaking the regex.
-CDG10620
Software Developer
Software Developer
#3
Posted 22 March 2011 - 06:23 AM
thanks, but the commas worked fine.
my solution works slightly better than yours :c-whistle: cuz it's smaller.
but it still isn't good enough because i don't know a generic regexp that will cover all things like !"·$%&/(/)=?¿`+`'¡ç´Ç¨´;.:,-_
and i have to use the literal '-' to cover the real '-'
so i did:
[a-z,A-Z,0-9,-]*
my solution works slightly better than yours :c-whistle: cuz it's smaller.
but it still isn't good enough because i don't know a generic regexp that will cover all things like !"·$%&/(/)=?¿`+`'¡ç´Ç¨´;.:,-_
and i have to use the literal '-' to cover the real '-'
so i did:
[a-z,A-Z,0-9,-]*
#4
Posted 22 March 2011 - 06:58 AM
You are very unclear on what you wish to match,
1) Ranges are delimited by values not commas, repeating them is a recoverable syntax error.
2) If you are wishing to capture all non-"words" (letters or numbers) in a string, then the character will be the following: \W
1) Ranges are delimited by values not commas, repeating them is a recoverable syntax error.
2) If you are wishing to capture all non-"words" (letters or numbers) in a string, then the character will be the following: \W
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#5
Posted 22 March 2011 - 09:59 AM
*shrug* I've never claimed to be a regex guru. Glad you found something that works for you.
-CDG10620
Software Developer
Software Developer
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









