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 2 1558
"CJM" <cj*******@news group.nospamwro te:
>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
"Tim Slattery" <Sl********@bls .govwrote in message
news:ai******** *************** *********@4ax.c om...
>
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:
domything()
And the regexp search assuming no case restriction would be,
|
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.
Or how can I replace the html &entities; in a string
"blablabla&blablabal&balbalbal" with the chars they mean using
re.sub? I found out they are stored in an dict . I though about this functionality:
|
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 whatever I do gets errors. The examples use
namespace regExp, but the supplied files use regexp, I've got it so that
it at least doesn't complain about namespaces but it then complains that
it can't find the match function. My stylesheet is:
|
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 "PRACTICO".
What's the best way to do this?
TIA,
|
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 string (when you don't enter any values) - this is wrong
d+ expression does not match, for example "g24" string - this is also wrong
www.regexplib.com test validator works fine for both cases, i.e. it is reporting "not match" for the...
| |
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 3 would fall into this category, for
example, but that's not a realistic situation anymore.
And if such a condition exists, then how do you guys handle validation using
regular expressions, if the browser lacks them?
For example:
|
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 example:
var re = /some(thing|or other)?.*(n(est)(?:ed)?.*(parens) )/
var text = "There were some nesting parens in the test";
alert (regExpPos (text, re, 3));
|
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 re module in python, since this one
takes the regexp as if were specified this way: '^<widget class=".*"
|
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
|
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' is not an appropriate
modifier for the test() function - test() searches the entire string
by default.
However, I would expect it to degrade gracefully. Instead, I seem to
be getting something as follows - using W3Schools handy page at :
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |