473,385 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

RegExp

CJM
I'm trying to validate and input field that allows an integer or a single
'*' character using regular expressions, but I'm not getting the results I'm
expecting.

I'm trying to match against the pattern "[^0-9]*|[^\*]", which I hoped would
translate to 'match against groups of the numbers (0-9) or against a single
*'. However, it's matching against character 1 for each of the examples
below when Global = False. When Global = True, it matches against character
2 for S4/S5, and against one after the last character for S1-S3.

I'm sure this is a simple one for the RegExp experts amongst us. Any
thoughts?

Thansk

CJM

'Code Snippet
Dim oRegExp, oExpMatch, s1, s2, s3, s4, s5

Set oRegExp = new RegExp

With oRegExp
s1 = "12345" 'valid
s2 = "*" 'valid
s3 = "12*" 'not valid
s4 = "ABC" 'not valid
s5 = "**" 'not valid

.Global = True
.Pattern = "[^0-9]*|[^\*]"
Set oExpMatch = oRegExp.Execute(s1)
Set oExpMatch = oRegExp.Execute(s2)
Set oExpMatch = oRegExp.Execute(s3)
Set oExpMatch = oRegExp.Execute(s4)
Set oExpMatch = oRegExp.Execute(s5)

Response.Write "Match " & oExpMatch.Count

End With

Set oExpMatch = nothing
Set oRegExp = nothing
Oct 19 '06 #1
2 1547
"CJM" <cj*******@newsgroup.nospamwrote:
>I'm trying to validate and input field that allows an integer or a single
'*' character using regular expressions, but I'm not getting the results I'm
expecting.
>I'm trying to match against the pattern "[^0-9]*|[^\*]", which I hoped would
translate to 'match against groups of the numbers (0-9) or against a single
*'.
>With oRegExp
s1 = "12345" 'valid
s2 = "*" 'valid
s3 = "12*" 'not valid
s4 = "ABC" 'not valid
s5 = "**" 'not valid
I'm not entirely sure what you're trying to get. I think you want to
match a string made entirely of digits, or a string consisting of a
single *.

You're quite close to that. The first thing you need to do is to
remove the beginning-of-line character (^) from the character classes.
Then specify one or more digits and have it match end-of-line:

"^([0-9]+|\*)$"

beginning of line, then either one or more digits or a single *, then
end of line.

--
Tim Slattery
MS MVP(DTS)
Sl********@bls.gov
Oct 19 '06 #2
CJM

"Tim Slattery" <Sl********@bls.govwrote in message
news:ai********************************@4ax.com...
>
I'm not entirely sure what you're trying to get. I think you want to
match a string made entirely of digits, or a string consisting of a
single *.
Yep, that's right.
You're quite close to that.
Surprising but reassuring!
The first thing you need to do is to
remove the beginning-of-line character (^) from the character classes.
Then specify one or more digits and have it match end-of-line:
Ah... I didn't know about/didn't understand about these end-of-line thingys.
"^([0-9]+|\*)$"
Needless to say, it works - thanks. But I've also broken it down and looked
at the structure, and it also makes sense, which is even better.
beginning of line, then either one or more digits or a single *, then
end of line.
Thanks Tims - very helpful.

CJM
Oct 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
5
by: Lukas Holcik | last post by:
Hi everyone! How can I simply search text for regexps (lets say <a href="(.*?)">(.*?)</a>) and save all URLs(1) and link contents(2) in a dictionary { name : URL}? In a single pass if it could....
0
by: Chris Croughton | last post by:
I'm trying to use the EXSLT regexp package from http://www.exslt.org/regexp/functions/match/index.html (specifically the match function) with the libxml xltproc (which supports EXSLT), but...
4
by: Jon Maz | last post by:
Hi All, I want to strip the accents off characters in a string so that, for example, the (Spanish) word "práctico" comes out as "practico" - but ignoring case, so that "PRÁCTICO" comes out as...
8
by: Dmitry Korolyov | last post by:
ASP.NET app using c# and framework version 1.1.4322.573 on a IIS 6.0 web server. A single-line asp:textbox control and regexp validator attached to it. ^\d+$ expression does match an empty...
26
by: Matt Kruse | last post by:
Are there any current browsers that have Javascript support, but not RegExp support? For example, cell phone browsers, blackberrys, or other "minimal" browsers? I know that someone using Netscape...
7
by: Csaba Gabor | last post by:
I need to come up with a function function regExpPos (text, re, parenNum) { ... } that will return the position within text of RegExp.$parenNum if there is a match, and -1 otherwise. For...
4
by: conan | last post by:
This regexp '<widget class=".*" id=".*">' works well with 'grep' for matching lines of the kind <widget class="GtkWindow" id="window1"> on a XML .glade file However that's not true for the...
6
by: runsun pan | last post by:
Hi I am wondering why I couldn't get what I want in the following 3 cases of re: (A) var p=/(+-?+):(+)/g p.exec("style='font-size:12'") -- // expected
4
by: Matt | last post by:
Hello all, I have just discovered (the long way) that using a RegExp object with the 'global' flag set produces inconsistent results when its test() method is executed. I realize that 'global'...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.