how to limit string length with RegExp?

how to limit string length with RegExp?

Post by Stev » Sun, 23 May 2004 05:59:39


Greetings,

I need to limit a string length between 1 to 2
characters. For the pattern I have
...
RE.IgnoreCase
RE.Pattern = "[a-z]{2}"

I want to capture like "a" or "aa" but not "aaa", or
capture "ab" ok, but not "abc" (more than 2 chars)
or "abb", etc. I can never figure out how to limit the
number of chars occuring in the pattern. Any suggestions
appreciated how to be able to limit the length of the
string between 1 to 2 chars (or just what the rule is for
limiting how many chars can occur in a pattern).

Thanks,
Steve
 
 
 

how to limit string length with RegExp?

Post by Stev » Sun, 23 May 2004 06:54:29

Well, I stumbled onto one pattersn that appears to work
for what I need

RE.Pattern = "^([a-z]){1,2}$"

I just don't like the idea that I am hacking away to get
this. Is there a rule? Or are they all just hacks?

 
 
 

how to limit string length with RegExp?

Post by MV » Sun, 23 May 2004 11:34:24

> I just don't like the idea that I am hacking away to get


If documentation = rules then
goto " http://www.yqcomputer.com/ "
install
read "VBScript / Introduction to Regular Expressions"
end if



--
Michael Harris
Microsoft.MVP.Scripting

MicrosoftWindows000 Scripting Guide
http://www.yqcomputer.com/

TechNet Script Center Sample Scripts
http://www.yqcomputer.com/

WSH 5.6 documentation download
http://www.yqcomputer.com/
 
 
 

how to limit string length with RegExp?

Post by Roland Hal » Mon, 24 May 2004 06:03:26


: I need to limit a string length between 1 to 2
: characters. For the pattern I have
: ...
: RE.IgnoreCase
: RE.Pattern = "[a-z]{2}"
:
: I want to capture like "a" or "aa" but not "aaa", or
: capture "ab" ok, but not "abc" (more than 2 chars)
: or "abb", etc. I can never figure out how to limit the
: number of chars occuring in the pattern. Any suggestions
: appreciated how to be able to limit the length of the
: string between 1 to 2 chars (or just what the rule is for
: limiting how many chars can occur in a pattern).

Do you want to truncate strings greater than 2 characters, to 2 characters
or do you want to only return characters that are 2 characters in length?
And, are you accepting any characters or just A-Za-z?

If this written in VBScript blocks or ASP?

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.yqcomputer.com/
WSH 5.6 Documentation - http://www.yqcomputer.com/
MSDN Library - http://www.yqcomputer.com/
 
 
 

how to limit string length with RegExp?

Post by Roland Hal » Mon, 24 May 2004 06:09:16


goto " http://www.yqcomputer.com/ "

should be...

goto
" http://www.yqcomputer.com/
-8A76-1C4099D7BBB9&displaylang=en"


--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.yqcomputer.com/
WSH 5.6 Documentation - http://www.yqcomputer.com/
MSDN Library - http://www.yqcomputer.com/