Hi,

I am putting together a quick (I hoped...) ASP page using VBScript to
parse some data, add some stuff up, and display it to a user.

Unfortunately, I had to whip the page together that took that data in
a big hurry and some fields were left blank. Now when I parse the
data, these empty fields are causing an error. Also, some people put
characters in where there were supposed to be numbers. Bad job on
developing the page to take the data on my part.

However, I am trying to just check to see if something is NOT a
number, and replace it with a 0. This will be fine for my needs. I
am getting zero matches on the regular expression! Forgive me, I am
not used to doing these in VBScript but have used regex in Perl and
JavaScript. I am not sure if I am just messing up or if it is a
VBScript nuance.

Set regExNum = New RegExp
regExNum.Pattern = "\D"
q1 = Split(record(fieldCount), ",")
for k=0 to UBOUND(q1)
if regExNum.Test(q1(k)) then
q1(k) = 0
end if
next

I am getting zero matches on this. For example, on particular
instance is an empty space that was not filled in and it is crashing
my select statement. I am getting a false on the comparison so the
replacement never takes place.

Thanks for any suggestions.

Re: VBScript Regular Expression by Pegasus

Pegasus
Wed Nov 28 09:09:16 PST 2007


"KDawg44" <KDawg44@gmail.com> wrote in message
news:dd68051b-9f6b-4cf3-be59-c8b68af66b87@g30g2000hsb.googlegroups.com...
> Hi,
>
> I am putting together a quick (I hoped...) ASP page using VBScript to
> parse some data, add some stuff up, and display it to a user.
>
> Unfortunately, I had to whip the page together that took that data in
> a big hurry and some fields were left blank. Now when I parse the
> data, these empty fields are causing an error. Also, some people put
> characters in where there were supposed to be numbers. Bad job on
> developing the page to take the data on my part.
>
> However, I am trying to just check to see if something is NOT a
> number, and replace it with a 0. This will be fine for my needs. I
> am getting zero matches on the regular expression! Forgive me, I am
> not used to doing these in VBScript but have used regex in Perl and
> JavaScript. I am not sure if I am just messing up or if it is a
> VBScript nuance.
>
> Set regExNum = New RegExp
> regExNum.Pattern = "\D"
> q1 = Split(record(fieldCount), ",")
> for k=0 to UBOUND(q1)
> if regExNum.Test(q1(k)) then
> q1(k) = 0
> end if
> next
>
> I am getting zero matches on this. For example, on particular
> instance is an empty space that was not filled in and it is crashing
> my select statement. I am getting a false on the comparison so the
> replacement never takes place.
>
> Thanks for any suggestions.

I would keep it simple and use the "IsNumeric" function.



Re: VBScript Regular Expression by KDawg44

KDawg44
Wed Nov 28 09:43:39 PST 2007

On Nov 28, 12:09 pm, "Pegasus \(MVP\)" <I....@fly.com> wrote:
> "KDawg44" <KDaw...@gmail.com> wrote in message
>
> news:dd68051b-9f6b-4cf3-be59-c8b68af66b87@g30g2000hsb.googlegroups.com...
>
>
>
> > Hi,
>
> > I am putting together a quick (I hoped...) ASP page using VBScript to
> > parse some data, add some stuff up, and display it to a user.
>
> > Unfortunately, I had to whip the page together that took that data in
> > a big hurry and some fields were left blank. Now when I parse the
> > data, these empty fields are causing an error. Also, some people put
> > characters in where there were supposed to be numbers. Bad job on
> > developing the page to take the data on my part.
>
> > However, I am trying to just check to see if something is NOT a
> > number, and replace it with a 0. This will be fine for my needs. I
> > am getting zero matches on the regular expression! Forgive me, I am
> > not used to doing these in VBScript but have used regex in Perl and
> > JavaScript. I am not sure if I am just messing up or if it is a
> > VBScript nuance.
>
> > Set regExNum = New RegExp
> > regExNum.Pattern = "\D"
> > q1 = Split(record(fieldCount), ",")
> > for k=0 to UBOUND(q1)
> > if regExNum.Test(q1(k)) then
> > q1(k) = 0
> > end if
> > next
>
> > I am getting zero matches on this. For example, on particular
> > instance is an empty space that was not filled in and it is crashing
> > my select statement. I am getting a false on the comparison so the
> > replacement never takes place.
>
> > Thanks for any suggestions.
>
> I would keep it simple and use the "IsNumeric" function.

Thanks! That works great. Didn't know that existed!

As usual, I am making problems more diffcult then they are.... :)

Thanks

Re: VBScript Regular Expression by ekkehard

ekkehard
Wed Nov 28 09:58:50 PST 2007

KDawg44 schrieb:
> Hi,
>
> I am putting together a quick (I hoped...) ASP page using VBScript to
> parse some data, add some stuff up, and display it to a user.
>
> Unfortunately, I had to whip the page together that took that data in
> a big hurry and some fields were left blank. Now when I parse the
> data, these empty fields are causing an error. Also, some people put
> characters in where there were supposed to be numbers. Bad job on
> developing the page to take the data on my part.
>
> However, I am trying to just check to see if something is NOT a
> number, and replace it with a 0. This will be fine for my needs. I
> am getting zero matches on the regular expression! Forgive me, I am
> not used to doing these in VBScript but have used regex in Perl and
> JavaScript. I am not sure if I am just messing up or if it is a
> VBScript nuance.
>
> Set regExNum = New RegExp
> regExNum.Pattern = "\D"
> q1 = Split(record(fieldCount), ",")
> for k=0 to UBOUND(q1)
> if regExNum.Test(q1(k)) then
> q1(k) = 0
> end if
> next
>
> I am getting zero matches on this. For example, on particular
> instance is an empty space that was not filled in and it is crashing
> my select statement. I am getting a false on the comparison so the
> replacement never takes place.
>
> Thanks for any suggestions.

Not knowing your data or your meaning of "empty space", I can't explain
why you get no match at all. That "\D" doesn't match "" ("^$") seems
reasonable, but letters should be caught.

Perhaps this:

Dim sTest : sTest = "1234, 1 ,,a, ,0,o,+12,12 xxx,12+12"
Dim aTest : aTest = Split( sTest, "," )
Dim oRE : Set oRE = New RegExp
oRE.Pattern = "\D"
' oRE.Pattern = "\D|^$"
Dim nIdx
For nIdx = 0 To UBound( aTest )
WScript.Echo "|" & aTest( nIdx ) & "|"
WScript.Echo "IsNumeric", CStr( IsNumeric( aTest( nIdx ) ) )
If oRE.Test( aTest( nIdx ) ) Then aTest( nIdx ) = "0 (Replaced)"
WScript.Echo "|" & aTest( nIdx ) & "|"
WScript.Echo
Next

output:

=== notNum: using RegExp to find non nums ========
|1234|
IsNumeric Wahr
|1234|

| 1 |
IsNumeric Wahr
|0 (Replaced)|

||
IsNumeric Falsch
||

|a|
IsNumeric Falsch
|0 (Replaced)|

| |
IsNumeric Falsch
|0 (Replaced)|

|0|
IsNumeric Wahr
|0|

|o|
IsNumeric Falsch
|0 (Replaced)|

|+12|
IsNumeric Wahr
|0 (Replaced)|

|12 xxx|
IsNumeric Falsch
|0 (Replaced)|

|12+12|
IsNumeric Falsch
|0 (Replaced)|

=== notNum: 0 done (00:00:00) ====================

will help you to decide whether to continue tinkering with the RegExp
or to switch to IsNumeric() as Pegasus proposed.

Re: VBScript Regular Expression by Alexander

Alexander
Wed Nov 28 12:26:02 PST 2007

KDawg44 schrieb:

> However, I am trying to just check to see if something is NOT a
> number, and replace it with a 0. I am not sure if I am just messing up or if it is a
> VBScript nuance.
>
> Set regExNum = New RegExp
> regExNum.Pattern = "\D"
> q1 = Split(record(fieldCount), ",")
> for k=0 to UBOUND(q1)
> if regExNum.Test(q1(k)) then
> q1(k) = 0
> end if
> next
>
> I am getting zero matches on this.

If your pattern is "\D" it will match a string that
consists of only *one* character and which is not numeric.
If you want detect non-numeric chars within longer strings,
set the global prop to true, or alter the pattern to ".*\D.*"


Dim r, arr, a, str

str = "A,test,4,1,string with,12324,chars"
Set r = New RegExp
r.Pattern = "\D"
r.Global = True
arr = Split(str, ",")
for i=0 to Ubound(arr)
if r.Test(arr(i)) then
arr(i) = 0
end if
next

msgbox join(arr)


Of course practically speaking, Pegasus' IsNumeric-approach will
probably satisfy all your needs.


MfG,
Alex

Re: VBScript Regular Expression by ekkehard

ekkehard
Wed Nov 28 12:33:47 PST 2007

Alexander Mueller schrieb:
> KDawg44 schrieb:
>
>> However, I am trying to just check to see if something is NOT a
>> number, and replace it with a 0. I am not sure if I am just messing
>> up or if it is a
>> VBScript nuance.
>>
>> Set regExNum = New RegExp
>> regExNum.Pattern = "\D"
>> q1 = Split(record(fieldCount), ",")
>> for k=0 to UBOUND(q1)
>> if regExNum.Test(q1(k)) then
>> q1(k) = 0
>> end if
>> next
>>
>> I am getting zero matches on this.
>
> If your pattern is "\D" it will match a string that
> consists of only *one* character and which is not numeric.

That's not true; "\D" matches a string that contains at least
one non numerical character. You need "^\D$" to match a string
that consists of exactly one non numerical character.

> If you want detect non-numeric chars within longer strings,
> set the global prop to true, or alter the pattern to ".*\D.*"
>
>
> Dim r, arr, a, str
>
> str = "A,test,4,1,string with,12324,chars"
> Set r = New RegExp
> r.Pattern = "\D"
> r.Global = True
> arr = Split(str, ",")
> for i=0 to Ubound(arr)
> if r.Test(arr(i)) then
> arr(i) = 0
> end if
> next
>
> msgbox join(arr)
>
>
> Of course practically speaking, Pegasus' IsNumeric-approach will
> probably satisfy all your needs.
>
>
> MfG,
> Alex

Re: VBScript Regular Expression by Anthony

Anthony
Thu Nov 29 03:22:52 PST 2007

"KDawg44" <KDawg44@gmail.com> wrote in message
news:536d976f-1995-4cf1-b7d2-d07fff13c5bf@g30g2000hsb.googlegroups.com...
> On Nov 28, 12:09 pm, "Pegasus \(MVP\)" <I....@fly.com> wrote:
> > "KDawg44" <KDaw...@gmail.com> wrote in message
> >
> >
news:dd68051b-9f6b-4cf3-be59-c8b68af66b87@g30g2000hsb.googlegroups.com...
> >
> >
> >
> > > Hi,
> >
> > > I am putting together a quick (I hoped...) ASP page using VBScript to
> > > parse some data, add some stuff up, and display it to a user.
> >
> > > Unfortunately, I had to whip the page together that took that data in
> > > a big hurry and some fields were left blank. Now when I parse the
> > > data, these empty fields are causing an error. Also, some people put
> > > characters in where there were supposed to be numbers. Bad job on
> > > developing the page to take the data on my part.
> >
> > > However, I am trying to just check to see if something is NOT a
> > > number, and replace it with a 0. This will be fine for my needs. I
> > > am getting zero matches on the regular expression! Forgive me, I am
> > > not used to doing these in VBScript but have used regex in Perl and
> > > JavaScript. I am not sure if I am just messing up or if it is a
> > > VBScript nuance.
> >
> > > Set regExNum = New RegExp
> > > regExNum.Pattern = "\D"
> > > q1 = Split(record(fieldCount), ",")
> > > for k=0 to UBOUND(q1)
> > > if regExNum.Test(q1(k)) then
> > > q1(k) = 0
> > > end if
> > > next
> >
> > > I am getting zero matches on this. For example, on particular
> > > instance is an empty space that was not filled in and it is crashing
> > > my select statement. I am getting a false on the comparison so the
> > > replacement never takes place.
> >
> > > Thanks for any suggestions.
> >
> > I would keep it simple and use the "IsNumeric" function.
>
> Thanks! That works great. Didn't know that existed!
>
> As usual, I am making problems more diffcult then they are.... :)
>

This sort of problem is usually caused by not consulting the manual:-

http://msdn2.microsoft.com/en-us/library/3ca8tfek.aspx

it might be worth your while just reviewing the available functions and
statements, they may give some more clues as to what is available.

--
Anthony Jones - MVP ASP/ASP.NET