ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Modifying regex to accept comma's? (https://www.excelbanter.com/excel-programming/430386-modifying-regex-accept-commas.html)

Simon Lloyd[_1165_]

Modifying regex to accept comma's?
 


Also posted he 'VBA Express Forum'
(http://www.vbaexpress.com/forum/showthread.php?t=27363)

Hi all i'm using regex (provided for me by some one else because i
don't have the foggiest with it) to force an entry of letters (at least
for the first two, rather than all numeric, however i want the user to
be able to enter the data in this fashion xxxxxx, xxxxxx where x will be
a character, however, using this ^[a-z]{2}[a-z ]*$ does not allow the
comma, can someone help modify it to accept it?


--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=110364


Ron Rosenfeld

Modifying regex to accept comma's?
 

On Fri, 26 Jun 2009 07:20:40 +0100, Simon Lloyd
wrote:


Also posted he 'VBA Express Forum'
(http://www.vbaexpress.com/forum/showthread.php?t=27363)

Hi all i'm using regex (provided for me by some one else because i
don't have the foggiest with it) to force an entry of letters (at least
for the first two, rather than all numeric, however i want the user to
be able to enter the data in this fashion xxxxxx, xxxxxx where x will be
a character, however, using this ^[a-z]{2}[a-z ]*$ does not allow the
comma, can someone help modify it to accept it?


From what you've presented, your regex only matches strings with start with two
lower case letters, and continues with only lower case letters or spaces. It
does not match numbers at all and, unless you have set your regex function to
ignore case, it will not match upper case letters either.

If you want to add the ability to also match commas, after the first two lower
case letters, then just add a comma to the second character class:

^[a-z]{2}[,a-z ]*$

If you want something different, you will have to be more specific.
--ron

Simon Lloyd[_1166_]

Modifying regex to accept comma's?
 


Thanks for the reply, i did want a mix of upper and lowercase, and yes i
did want to force the first two characters to be letters and i do not
want numbers at all, should it look like this for mixed
^[Aa-Zz]{2}[,Aa-Zz ]*$
Ron Rosenfeld;395256 Wrote:
On Fri, 26 Jun 2009 07:20:40 +0100, Simon Lloyd
wrote:


Also posted he 'VBA Express Forum'
('VBA Express Forum'

(http://www.vbaexpress.com/forum/showthread.php?t=27363))

Hi all i'm using regex (provided for me by some one else because i
don't have the foggiest with it) to force an entry of letters (at

least
for the first two, rather than all numeric, however i want the user to
be able to enter the data in this fashion xxxxxx, xxxxxx where x will

be
a character, however, using this ^[a-z]{2}[a-z ]*$ does not allow the
comma, can someone help modify it to accept it?


From what you've presented, your regex only matches strings with start
with two
lower case letters, and continues with only lower case letters or
spaces. It
does not match numbers at all and, unless you have set your regex
function to
ignore case, it will not match upper case letters either.

If you want to add the ability to also match commas, after the first
two lower
case letters, then just add a comma to the second character class:

^[a-z]{2}[,a-z ]*$

If you want something different, you will have to be more specific.
--ron



--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=110364


Simon Lloyd[_1167_]

Modifying regex to accept comma's?
 


Simon Lloyd;395563 Wrote:
Thanks for the reply, i did want a mix of upper and lowercase, and yes i
did want to force the first two characters to be letters and i do not
want numbers at all, should it look like this for mixed
^[Aa-Zz]{2}[,Aa-Zz ]*$Aha!, got it with some playing around!

^[A-Za-z]{2}[,A-Za-z ]*$


--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=110364


Ron Rosenfeld

Modifying regex to accept comma's?
 

On Fri, 26 Jun 2009 16:53:05 +0100, Simon Lloyd
wrote:

Aha!, got it with some playing around!
^[A-Za-z]{2}[,A-Za-z ]*$


That should work.

Here are some links you may find useful (if they are still good :-))

Regular Expressions
http://www.regular-expressions.info/reference.html
http://support.microsoft.com/default...02&Product=vbb
http://msdn2.microsoft.com/en-us/library/6wzad2b2.aspx
http://msdn2.microsoft.com/en-us/library/ms974619.aspx
http://www.regex-guru.info/
--ron

Simon Lloyd[_1168_]

Modifying regex to accept comma's?
 


Ron much appreciated thanks :)Ron Rosenfeld;395805 Wrote:
On Fri, 26 Jun 2009 16:53:05 +0100, Simon Lloyd
wrote:

Aha!, got it with some playing around!
^[A-Za-z]{2}[,A-Za-z ]*$


That should work.

Here are some links you may find useful (if they are still good :-))

Regular Expressions
'Regular Expressions Reference - Basic Syntax'
(http://www.regular-expressions.info/reference.html)
'How To Use Regular Expressions in Microsoft Visual Basic 6.0'
(http://tinyurl.com/kwem2c)
'Introduction to Regular Expressions (Scripting)'
(http://msdn2.microsoft.com/en-us/library/6wzad2b2.aspx)
'What's New in Windows Script 5.5'
(http://msdn2.microsoft.com/en-us/library/ms974619.aspx)
'Regex Guru' (http://www.regex-guru.info/)
--ron



--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=110364



All times are GMT +1. The time now is 02:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com