gum1982 Posted January 25, 2010 Share Posted January 25, 2010 Can someone please help me. Ive done this regular expression which works out as any code that starts with two letters and ends with four numbers. i.e as1233 Im not very good with regular expressions all i want is it to allow spaces because the company has hand out the code to every as two letters SPACE and ends with four numbers. ie as 1233 Here my regular expression ("^[[a-zA-Z]{2}[0-9]{4}]$") i see that \s strips whitespace but dont now how to implement this. Any help Please? Quote Link to comment https://forums.phpfreaks.com/topic/189762-delete-whitespace/ Share on other sites More sharing options...
wildteen88 Posted January 25, 2010 Share Posted January 25, 2010 \s doesn't strip white space. \s matches any whitespace character, eg a space, newline, tab etc. To match a space add \s before [0-9] eg ("^[[a-zA-Z]{2}\s[0-9]{4}]$") Alternatively you could just add a space instead ("^[[a-zA-Z]{2} [0-9]{4}]$") Quote Link to comment https://forums.phpfreaks.com/topic/189762-delete-whitespace/#findComment-1001434 Share on other sites More sharing options...
gum1982 Posted January 25, 2010 Author Share Posted January 25, 2010 thanks for the reply So if i add this ("^[[a-zA-Z]{2}\s[0-9]{4}]$") does this mean that both possible codes would work? ie as1233 or as 1233 Quote Link to comment https://forums.phpfreaks.com/topic/189762-delete-whitespace/#findComment-1001435 Share on other sites More sharing options...
wildteen88 Posted January 25, 2010 Share Posted January 25, 2010 Add a ? after \s That way it will match either as1233 or as 1233 Quote Link to comment https://forums.phpfreaks.com/topic/189762-delete-whitespace/#findComment-1001442 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.