473,413 Members | 1,778 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,413 software developers and data experts.

Regular expression for validating [GrandTotal]=4*[TotalCharges]+[currentCharges]+2

Hi Friends,

I'm constructing a regular expression for validating an expression
which looks as any of the following forms:

1. [GrandTotal]=4*[TotalCharges]+[currentCharges]+2
OR
2. [TotalCharges]=Sum([CurrentCharges])*6

Some of the samples I have constructed below:

StringEx RegEx
[alphaNumeric] --- ^\[[a-zA-Z]+[0-9]*\]$
[TotalCharges]+2 --- ^\[[a-zA-Z]+[0-9]*\](\
+[0-9]*)*$
[TotalCharges]/22+5/6*8---^\[[a-zA-Z]+[0-9]*\]([\+\-\*\/][0-9]*)*$
[TotalCharges]/22+5/6*8+[currChrgs] ---->^\[[a-zA-Z]+[0-9]*\]([\+\-\*
\/][0-9]*)*([\+\-\*\/]\[[a-zA-Z]+[0-9]*\])*$
2*[TotalCharges]/22+5/6*8+[currChrgs] ----->^([0-9]*[\+\-\*\/])*\[[a-
zA-Z]+[0-9]*\]([\+\-\*\/][0-9]*)*([\+\-\*\/]\[[a-zA-Z]+[0-9]*\])*$

Pls help me... I'm badly in need of this in my project.

Thanks in advance...
Venu.

Nov 6 '07 #1
10 1641
Hello ve************@gmail.com,
Hi Friends,

I'm constructing a regular expression for validating an expression
which looks as any of the following forms:

1. [GrandTotal]=4*[TotalCharges]+[currentCharges]+2
OR
2. [TotalCharges]=Sum([CurrentCharges])*6
Some of the samples I have constructed below:

StringEx RegEx
[alphaNumeric] --- ^\[[a-zA-Z]+[0-9]*\]$
[TotalCharges]+2 --- ^\[[a-zA-Z]+[0-9]*\](\
+[0-9]*)*$
[TotalCharges]/22+5/6*8---^\[[a-zA-Z]+[0-9]*\]([\+\-\*\/][0-9]*)*$
[TotalCharges]/22+5/6*8+[currChrgs] ---->^\[[a-zA-Z]+[0-9]*\]([\+\-\*
\/][0-9]*)*([\+\-\*\/]\[[a-zA-Z]+[0-9]*\])*$
2*[TotalCharges]/22+5/6*8+[currChrgs] ----->^([0-9]*[\+\-\*\/])*\[[a-
zA-Z]+[0-9]*\]([\+\-\*\/][0-9]*)*([\+\-\*\/]\[[a-zA-Z]+[0-9]*\])*$
Pls help me... I'm badly in need of this in my project.
A parser would be a much better solutio than a regular expression. Microsoft
recently started shipping Mplex/MPPG with the Visual Studio SDK, you might
be able to use these

http://www.google.nl/search?q=mplex+...ient=firefox-a

though the following might work:
(?<var\[[^\]]) = ([0-9]+|[[^\]]|(sum|avg|count)\([0-9]+|[[^\]]\))([+/*-]([0-9]+|[[^\]]|(sum|avg|count)\([0-9]+|[[^\]]\)))*

It does not take nested functions into account, nor does it allow complex
expressions inside a function (sum|avg|count). You might be able to get it
working.

Good luck :)

--
Jesse Houwing
jesse.houwing at sogeti.nl
Nov 6 '07 #2
On Nov 6, 2:53 pm, Jesse Houwing <jesse.houw...@newsgroup.nospam>
wrote:
Hello venugopal.s...@gmail.com,


Hi Friends,
I'm constructing a regular expression for validating an expression
which looks as any of the following forms:
1. [GrandTotal]=4*[TotalCharges]+[currentCharges]+2
OR
2. [TotalCharges]=Sum([CurrentCharges])*6
Some of the samples I have constructed below:
StringEx RegEx
[alphaNumeric] --- ^\[[a-zA-Z]+[0-9]*\]$
[TotalCharges]+2 --- ^\[[a-zA-Z]+[0-9]*\](\
+[0-9]*)*$
[TotalCharges]/22+5/6*8---^\[[a-zA-Z]+[0-9]*\]([\+\-\*\/][0-9]*)*$
[TotalCharges]/22+5/6*8+[currChrgs] ---->^\[[a-zA-Z]+[0-9]*\]([\+\-\*
\/][0-9]*)*([\+\-\*\/]\[[a-zA-Z]+[0-9]*\])*$
2*[TotalCharges]/22+5/6*8+[currChrgs] ----->^([0-9]*[\+\-\*\/])*\[[a-
zA-Z]+[0-9]*\]([\+\-\*\/][0-9]*)*([\+\-\*\/]\[[a-zA-Z]+[0-9]*\])*$
Pls help me... I'm badly in need of this in my project.

A parser would be a much better solutio than a regular expression. Microsoft
recently started shipping Mplex/MPPG with the Visual Studio SDK, you might
be able to use these

http://www.google.nl/search?q=mplex+...f-8&aq=t&rls=o...

though the following might work:
(?<var\[[^\]]) = ([0-9]+|[[^\]]|(sum|avg|count)\([0-9]+|[[^\]]\))([+/*-]([0-9]+|[[^\]]|(sum|*avg|count)\([0-9]+|[[^\]]\)))*

It does not take nested functions into account, nor does it allow complex
expressions inside a function (sum|avg|count). You might be able to get it
working.

Good luck :)

--
Jesse Houwing
jesse.houwing at sogeti.nl- Hide quoted text -

- Show quoted text -

Hi Jesse,

(?<var\[[^\]]) = ([0-9]+|[[^\]]|(sum|avg|count)\([0-9]+|[[^\]]\))([+/
*-]([0-9]+|[[^\]]|(sum|*avg|count)\([0-9]+|[[^\]]\)))*

(?<var\[[^\]]) is giving the error as invalid group name..

Nov 6 '07 #3
Hello ve************@gmail.com,
On Nov 6, 2:53 pm, Jesse Houwing <jesse.houw...@newsgroup.nospam>
wrote:
>Hello venugopal.s...@gmail.com,
>>Hi Friends,

I'm constructing a regular expression for validating an expression
which looks as any of the following forms:

1. [GrandTotal]=4*[TotalCharges]+[currentCharges]+2
OR
2. [TotalCharges]=Sum([CurrentCharges])*6
Some of the samples I have constructed below:
StringEx RegEx
[alphaNumeric] --->
^\[[a-zA-Z]+[0-9]*\]$
[TotalCharges]+2 --->
^\[[a-zA-Z]+[0-9]*\](\
+[0-9]*)*$
[TotalCharges]/22+5/6*8---^\[[a-zA-Z]+[0-9]*\]([\+\-\*\/][0-9]*)*$
[TotalCharges]/22+5/6*8+[currChrgs]
---->^\[[a-zA-Z]+[0-9]*\]([\+\-\*
\/][0-9]*)*([\+\-\*\/]\[[a-zA-Z]+[0-9]*\])*$
2*[TotalCharges]/22+5/6*8+[currChrgs]
----->^([0-9]*[\+\-\*\/])*\[[a-
zA-Z]+[0-9]*\]([\+\-\*\/][0-9]*)*([\+\-\*\/]\[[a-zA-Z]+[0-9]*\])*$
Pls help me... I'm badly in need of this in my project.
A parser would be a much better solutio than a regular expression.
Microsoft recently started shipping Mplex/MPPG with the Visual Studio
SDK, you might be able to use these

http://www.google.nl/search?q=mplex+...f-8&aq=t&rls=o
...

though the following might work:
(?<var\[[^\]]) =
([0-9]+|[[^\]]|(sum|avg|count)\([0-9]+|[[^\]]\))([+/*-]([0-9]+|[[^\]]
|(sum|?avg|count)\([0-9]+|[[^\]]\)))*
It does not take nested functions into account, nor does it allow
complex expressions inside a function (sum|avg|count). You might be
able to get it working.

Good luck :)

--
Jesse Houwing
jesse.houwing at sogeti.nl- Hide quoted text -
- Show quoted text -
Hi Jesse,

(?<var\[[^\]]) = ([0-9]+|[[^\]]|(sum|avg|count)\([0-9]+|[[^\]]\))([+/
*-]([0-9]+|[[^\]]|(sum|?avg|count)\([0-9]+|[[^\]]\)))*

(?<var\[[^\]]) is giving the error as invalid group name..
Seems I lost a in there

(?<var>\[[^\]])

And made a few errors on the way. I guess it happened when going from one
virtual pc to the next. I tested and expanded the expression and this is
what I ended up with:

\[[^\]]*\][ ]*=[ ]*([0-9]+|\[[^\]]*\]|(sum|avg|count)\([ ]*([0-9]+|\[[^\]]*\])[
]*\))([ ]*[-+*/][ ]*([0-9]+|\[[^\]]*\]|(sum|avg|count)\([ ]*([0-9]+|\[[^\]]*\])[
]*\)))*

Tested this time ;)
--
Jesse Houwing
jesse.houwing at sogeti.nl
Nov 6 '07 #4
On Nov 6, 4:51 pm, Jesse Houwing <jesse.houw...@newsgroup.nospam>
wrote:
Hello venugopal.s...@gmail.com,


On Nov 6, 2:53 pm, Jesse Houwing <jesse.houw...@newsgroup.nospam>
wrote:
Hello venugopal.s...@gmail.com,
>Hi Friends,
>I'm constructing a regular expression for validating an expression
which looks as any of the following forms:
>1. [GrandTotal]=4*[TotalCharges]+[currentCharges]+2
OR
2. [TotalCharges]=Sum([CurrentCharges])*6
Some of the samples I have constructed below:
StringEx RegEx
[alphaNumeric] --->
^\[[a-zA-Z]+[0-9]*\]$
[TotalCharges]+2 --->
^\[[a-zA-Z]+[0-9]*\](\
+[0-9]*)*$
[TotalCharges]/22+5/6*8---^\[[a-zA-Z]+[0-9]*\]([\+\-\*\/][0-9]*)*$
[TotalCharges]/22+5/6*8+[currChrgs]
---->^\[[a-zA-Z]+[0-9]*\]([\+\-\*
\/][0-9]*)*([\+\-\*\/]\[[a-zA-Z]+[0-9]*\])*$
2*[TotalCharges]/22+5/6*8+[currChrgs]
----->^([0-9]*[\+\-\*\/])*\[[a-
zA-Z]+[0-9]*\]([\+\-\*\/][0-9]*)*([\+\-\*\/]\[[a-zA-Z]+[0-9]*\])*$
Pls help me... I'm badly in need of this in my project.
A parser would be a much better solutio than a regular expression.
Microsoft recently started shipping Mplex/MPPG with the Visual Studio
SDK, you might be able to use these
>http://www.google.nl/search?q=mplex+...f-8&aq=t&rls=o
...
though the following might work:
(?<var\[[^\]]) =
([0-9]+|[[^\]]|(sum|avg|count)\([0-9]+|[[^\]]\))([+/*-]([0-9]+|[[^\]]
|(sum|?avg|count)\([0-9]+|[[^\]]\)))*
It does not take nested functions into account, nor does it allow
complex expressions inside a function (sum|avg|count). You might be
able to get it working.
Good luck :)
--
Jesse Houwing
jesse.houwing at sogeti.nl- Hide quoted text -
- Show quoted text -
Hi Jesse,
(?<var\[[^\]]) = ([0-9]+|[[^\]]|(sum|avg|count)\([0-9]+|[[^\]]\))([+/
*-]([0-9]+|[[^\]]|(sum|?avg|count)\([0-9]+|[[^\]]\)))*
(?<var\[[^\]]) is giving the error as invalid group name..

Seems I lost a in there

(?<var>\[[^\]])

And made a few errors on the way. I guess it happened when going from one
virtual pc to the next. I tested and expanded the expression and this is
what I ended up with:

\[[^\]]*\][ ]*=[ ]*([0-9]+|\[[^\]]*\]|(sum|avg|count)\([ ]*([0-9]+|\[[^\]]*\])[
]*\))([ ]*[-+*/][ ]*([0-9]+|\[[^\]]*\]|(sum|avg|count)\([ ]*([0-9]+|\[[^\]]*\])[
]*\)))*

Tested this time ;)

--
Jesse Houwing
jesse.houwing at sogeti.nl- Hide quoted text -

- Show quoted text -
Hi Jesse,

Thank you very much. It's working. I Just made the following change:
^\[[a-zA-z]+([0-9])*\][ ]*=[ ]*([0-9]+|\[[a-zA-z]+([0-9])*\]|(sum|avg|
count)\([ ]*([0-9]+|\[[a-zA-z]+([0-9])*\])[
]*\))([ ]*[-+*/][ ]*([0-9]+|\[[a-zA-z]+([0-9])*\]|(sum|avg|count)\
([ ]*([0-9]+|\[[a-zA-z]+([0-9])*\])[
]*\)))*$

because, earlier it was taking space inside [ and ] like [current
charges].

let's see together for further improvement of this :)

Thanks and Regards,
Venu
venugopal.sjce at gmail.com

Nov 7 '07 #5
Hello ve************@gmail.com,
On Nov 6, 4:51 pm, Jesse Houwing <jesse.houw...@newsgroup.nospam>
wrote:
>Hello venugopal.s...@gmail.com,
>>On Nov 6, 2:53 pm, Jesse Houwing <jesse.houw...@newsgroup.nospam>
wrote:

Hello venugopal.s...@gmail.com,

Hi Friends,
>
I'm constructing a regular expression for validating an expression
which looks as any of the following forms:
>
1. [GrandTotal]=4*[TotalCharges]+[currentCharges]+2
OR
2. [TotalCharges]=Sum([CurrentCharges])*6
Some of the samples I have constructed below:
StringEx RegEx
[alphaNumeric] --->
^\[[a-zA-Z]+[0-9]*\]$
[TotalCharges]+2 --->
^\[[a-zA-Z]+[0-9]*\](\
+[0-9]*)*$
[TotalCharges]/22+5/6*8--->
^\[[a-zA-Z]+[0-9]*\]([\+\-\*\/][0-9]*)*$
[TotalCharges]/22+5/6*8+[currChrgs]
---->^\[[a-zA-Z]+[0-9]*\]([\+\-\*
\/][0-9]*)*([\+\-\*\/]\[[a-zA-Z]+[0-9]*\])*$
2*[TotalCharges]/22+5/6*8+[currChrgs]
----->^([0-9]*[\+\-\*\/])*\[[a-
zA-Z]+[0-9]*\]([\+\-\*\/][0-9]*)*([\+\-\*\/]\[[a-zA-Z]+[0-9]*\])*$
Pls help me... I'm badly in need of this in my project.
A parser would be a much better solutio than a regular expression.
Microsoft recently started shipping Mplex/MPPG with the Visual
Studio SDK, you might be able to use these

http://www.google.nl/search?q=mplex+...utf-8&aq=t&rls
=o ...

though the following might work:
(?<var\[[^\]]) =
([0-9]+|[[^\]]|(sum|avg|count)\([0-9]+|[[^\]]\))([+/*-]([0-9]+|[[^\
]]
|(sum|?avg|count)\([0-9]+|[[^\]]\)))*
It does not take nested functions into account, nor does it allow
complex expressions inside a function (sum|avg|count). You might be
able to get it working.
Good luck :)

--
Jesse Houwing
jesse.houwing at sogeti.nl- Hide quoted text -
- Show quoted text -
Hi Jesse,

(?<var\[[^\]]) =
([0-9]+|[[^\]]|(sum|avg|count)\([0-9]+|[[^\]]\))([+/
*-]([0-9]+|[[^\]]|(sum|?avg|count)\([0-9]+|[[^\]]\)))*

(?<var\[[^\]]) is giving the error as invalid group name..
Seems I lost a in there

(?<var>\[[^\]])

And made a few errors on the way. I guess it happened when going from
one virtual pc to the next. I tested and expanded the expression and
this is what I ended up with:

\[[^\]]*\][ ]*=[ ]*([0-9]+|\[[^\]]*\]|(sum|avg|count)\([
]*([0-9]+|\[[^\]]*\])[ ]*\))([ ]*[-+*/][
]*([0-9]+|\[[^\]]*\]|(sum|avg|count)\([ ]*([0-9]+|\[[^\]]*\])[
]*\)))*

Tested this time ;)

--
Jesse Houwing
jesse.houwing at sogeti.nl- Hide quoted text -
- Show quoted text -
Hi Jesse,

Thank you very much. It's working.
You;re very welcome :)
I Just made the following change:
^\[[a-zA-z]+([0-9])*\][ ]*=[ ]*([0-9]+|\[[a-zA-z]+([0-9])*\]|(sum|avg|
count)\([ ]*([0-9]+|\[[a-zA-z]+([0-9])*\])[
]*\))([ ]*[-+*/][ ]*([0-9]+|\[[a-zA-z]+([0-9])*\]|(sum|avg|count)\
([ ]*([0-9]+|\[[a-zA-z]+([0-9])*\])[
]*\)))*$
because, earlier it was taking space inside [ and ] like [current
charges].
It would accept anything between [] except a ]. :).
let's see together for further improvement of this :)
Keep me posted. I'm monitoring this group on a regular basis, if you include
the word regex it should light up automatically :).
--
Jesse Houwing
jesse.houwing at sogeti.nl
Nov 7 '07 #6
On Nov 7, 3:02 pm, Jesse Houwing <jesse.houw...@newsgroup.nospam>
wrote:
Hello venugopal.s...@gmail.com,


On Nov 6, 4:51 pm, Jesse Houwing <jesse.houw...@newsgroup.nospam>
wrote:
Hello venugopal.s...@gmail.com,
>On Nov 6, 2:53 pm, Jesse Houwing <jesse.houw...@newsgroup.nospam>
wrote:
>>Hello venugopal.s...@gmail.com,
>>>Hi Friends,
>>>I'm constructing a regular expression for validating an expression
which looks as any of the following forms:
>>>1. [GrandTotal]=4*[TotalCharges]+[currentCharges]+2
OR
2. [TotalCharges]=Sum([CurrentCharges])*6
Some of the samples I have constructed below:
StringEx RegEx
[alphaNumeric] --->
^\[[a-zA-Z]+[0-9]*\]$
[TotalCharges]+2 --->
^\[[a-zA-Z]+[0-9]*\](\
+[0-9]*)*$
[TotalCharges]/22+5/6*8--->
^\[[a-zA-Z]+[0-9]*\]([\+\-\*\/][0-9]*)*$
[TotalCharges]/22+5/6*8+[currChrgs]
---->^\[[a-zA-Z]+[0-9]*\]([\+\-\*
\/][0-9]*)*([\+\-\*\/]\[[a-zA-Z]+[0-9]*\])*$
2*[TotalCharges]/22+5/6*8+[currChrgs]
----->^([0-9]*[\+\-\*\/])*\[[a-
zA-Z]+[0-9]*\]([\+\-\*\/][0-9]*)*([\+\-\*\/]\[[a-zA-Z]+[0-9]*\])*$
Pls help me... I'm badly in need of this in my project.
A parser would be a much better solutio than a regular expression.
Microsoft recently started shipping Mplex/MPPG with the Visual
Studio SDK, you might be able to use these
>>>http://www.google.nl/search?q=mplex+...utf-8&aq=t&rls
=o ...
>>though the following might work:
(?<var\[[^\]]) =
([0-9]+|[[^\]]|(sum|avg|count)\([0-9]+|[[^\]]\))([+/*-]([0-9]+|[[^\
]]
|(sum|?avg|count)\([0-9]+|[[^\]]\)))*
It does not take nested functions into account, nor does it allow
complex expressions inside a function (sum|avg|count). You might be
able to get it working.
Good luck :)
>>--
Jesse Houwing
jesse.houwing at sogeti.nl- Hide quoted text -
- Show quoted text -
Hi Jesse,
>(?<var\[[^\]]) =
([0-9]+|[[^\]]|(sum|avg|count)\([0-9]+|[[^\]]\))([+/
*-]([0-9]+|[[^\]]|(sum|?avg|count)\([0-9]+|[[^\]]\)))*
>(?<var\[[^\]]) is giving the error as invalid group name..
Seems I lost a in there
(?<var>\[[^\]])
And made a few errors on the way. I guess it happened when going from
one virtual pc to the next. I tested and expanded the expression and
this is what I ended up with:
\[[^\]]*\][ ]*=[ ]*([0-9]+|\[[^\]]*\]|(sum|avg|count)\([
]*([0-9]+|\[[^\]]*\])[ ]*\))([ ]*[-+*/][
]*([0-9]+|\[[^\]]*\]|(sum|avg|count)\([ ]*([0-9]+|\[[^\]]*\])[
]*\)))*
Tested this time ;)
--
Jesse Houwing
jesse.houwing at sogeti.nl- Hide quoted text -
- Show quoted text -
Hi Jesse,
Thank you very much. It's working.

You;re very welcome :)
I Just made the following change:
^\[[a-zA-z]+([0-9])*\][ ]*=[ ]*([0-9]+|\[[a-zA-z]+([0-9])*\]|(sum|avg|
count)\([ ]*([0-9]+|\[[a-zA-z]+([0-9])*\])[
]*\))([ ]*[-+*/][ ]*([0-9]+|\[[a-zA-z]+([0-9])*\]|(sum|avg|count)\
([ ]*([0-9]+|\[[a-zA-z]+([0-9])*\])[
]*\)))*$
because, earlier it was taking space inside [ and ] like [current
charges].

It would accept anything between [] except a ]. :).
let's see together for further improvement of this :)

Keep me posted. I'm monitoring this group on a regular basis, if you include
the word regex it should light up automatically :).
--
Jesse Houwing
jesse.houwing at sogeti.nl- Hide quoted text -

- Show quoted text -
Hi Jesse,

The RegEx matches when we give whole numbers as in the expression
2+[jh] + 2 + 6 * [sssdsf323] + 2 * 3 + [dd] + 2 + [p] + SuM([ab]) * 9
+ AVG( [a] ).

I changed the RegEx as below to include decimal numbers as
[totalChrgs] + 2.3 * 5.67. The RegEx is as below.

^([0-9]+(\.\d{2})?|\[[a-zA-z]+([0-9])*\]|([Ss][Uu][Mm]|[Aa][Vv][Gg]|
[Cc][Oo][Uu][Nn][Tt])\([ ]*([0-9]+(\.\d{2})?|\[[a-zA-z]+([0-9])*\])[
]*\))([ ]*[-+*/][ ]*([0-9]+(\.\d{2})?|\[[a-zA-z]+([0-9])*\]|([Ss][Uu]
[Mm]|[Aa][Vv][Gg]|[Cc][Oo][Uu][Nn][Tt])\([ ]*([0-9]+(\.\d{2})?|\[[a-zA-
z]+([0-9])*\])[
]*\)))*$

But it is not matching with the expression. What could be the problem?

Reply soon,

Thanks and regards,
Venu

Nov 11 '07 #7
Hello Venu,

Hi Jesse,

The RegEx matches when we give whole numbers as in the expression 2+[jh]
+ 2 + 6 * [sssdsf323] + 2 * 3 + [dd] + 2 + [p] + SuM([ab]) * 9 + AVG( [a] ).
>
I changed the RegEx as below to include decimal numbers as [totalChrgs]
+ 2.3 * 5.67. The RegEx is as below.
>
^([0-9]+(\.\d{2})?|\[[a-zA-z]+([0-9])*\]|([Ss][Uu][Mm]|[Aa][Vv][Gg]|
[Cc][Oo][Uu][Nn][Tt])\([ ]*([0-9]+(\.\d{2})?|\[[a-zA-z]+([0-9])*\])[
]*\))([ ]*[-+*/][ ]*([0-9]+(\.\d{2})?|\[[a-zA-z]+([0-9])*\]|([Ss][Uu]
[Mm]|[Aa][Vv][Gg]|[Cc][Oo][Uu][Nn][Tt])\([ ]*([0-9]+(\.\d{2})?|\[[a-zA-
z]+([0-9])*\])[
]*\)))*$

But it is not matching with the expression. What could be the problem?

Reply soon,

Thanks and regards,
Venu
Change \.\d{2} in \.\d{1,} or \.\d{1,2} to allow one or more number(s) after
the decimal point. Currently the regex only matches if there are exactly
2 numbers after the point.

Also note that you can rewrite this:

Jesse

--
Jesse Houwing
jesse.houwing at sogeti.nl
Nov 11 '07 #8
Hello Venu,

Hi Jesse,

The RegEx matches when we give whole numbers as in the expression 2+[jh]
+ 2 + 6 * [sssdsf323] + 2 * 3 + [dd] + 2 + [p] + SuM([ab]) * 9 + AVG( [a] ).
>
I changed the RegEx as below to include decimal numbers as [totalChrgs]
+ 2.3 * 5.67. The RegEx is as below.
>
^([0-9]+(\.\d{2})?|\[[a-zA-z]+([0-9])*\]|([Ss][Uu][Mm]|[Aa][Vv][Gg]|
[Cc][Oo][Uu][Nn][Tt])\([ ]*([0-9]+(\.\d{2})?|\[[a-zA-z]+([0-9])*\])[
]*\))([ ]*[-+*/][ ]*([0-9]+(\.\d{2})?|\[[a-zA-z]+([0-9])*\]|([Ss][Uu]
[Mm]|[Aa][Vv][Gg]|[Cc][Oo][Uu][Nn][Tt])\([ ]*([0-9]+(\.\d{2})?|\[[a-zA-
z]+([0-9])*\])[
]*\)))*$

But it is not matching with the expression. What could be the problem?

Reply soon,

Thanks and regards,
Venu
Change \.\d{2} in \.\d{1,} or \.\d{1,2} to allow one or more number(s) after
the decimal point. Currently the regex only matches if there are exactly
2 numbers after the point.

Also consider rewriting \d as [0-9], I find it more readable and it's one
of the few times I make an exclusion to the rule mentioned below.

Also note that you can rewrite this:
[a-zA-z]+([0-9])*

as

[a-zA-z]+[0-9]* (I usually say that in case of a regex, shorter is better).
Jesse

--
Jesse Houwing
jesse.houwing at sogeti.nl
Nov 11 '07 #9
On Nov 12 2007, 12:15 am, Jesse Houwing
<jesse.houw...@newsgroup.nospamwrote:
Hello Venu,
Hi Jesse,
The RegEx matches when we give whole numbers as in the expression 2+[jh]

+ 2 + 6 * [sssdsf323] + 2 * 3 + [dd] + 2 + [p] + SuM([ab]) * 9 + AVG( [a] ).
I changed the RegEx as below to include decimal numbers as [totalChrgs]

+ 2.3 * 5.67. The RegEx is as below.
^([0-9]+(\.\d{2})?|\[[a-zA-z]+([0-9])*\]|([Ss][Uu][Mm]|[Aa][Vv][Gg]|
[Cc][Oo][Uu][Nn][Tt])\([ ]*([0-9]+(\.\d{2})?|\[[a-zA-z]+([0-9])*\])[
]*\))([ ]*[-+*/][ ]*([0-9]+(\.\d{2})?|\[[a-zA-z]+([0-9])*\]|([Ss][Uu]
[Mm]|[Aa][Vv][Gg]|[Cc][Oo][Uu][Nn][Tt])\([ ]*([0-9]+(\.\d{2})?|\[[a-zA-
z]+([0-9])*\])[
]*\)))*$
But it is not matching with the expression. What could be the problem?
Reply soon,
Thanks and regards,
Venu

Change \.\d{2} in \.\d{1,} or \.\d{1,2} to allow one or more number(s) after
the decimal point. Currently the regex only matches if there are exactly
2 numbers after the point.

Also consider rewriting \d as [0-9], I find it more readable and it's one
of the few times I make an exclusion to the rule mentioned below.

Also note that you can rewrite this:
[a-zA-z]+([0-9])*

as

[a-zA-z]+[0-9]* (I usually say that in case of a regex, shorter is better).

Jesse

--
Jesse Houwing
jesse.houwing at sogeti.nl
Hi Jesse, how are you doing?
How can we incorporate an expression like this in our regular
expression?
((([col1]+[col2])*[col3])/5)

Thanks,
Venu
Jan 10 '08 #10
Hello Venu,
On Nov 12 2007, 12:15 am, Jesse Houwing
<jesse.houw...@newsgroup.nospamwrote:
>Hello Venu,
>>Hi Jesse,

The RegEx matches when we give whole numbers as in the expression
2+[jh]
+ 2 + 6 * [sssdsf323] + 2 * 3 + [dd] + 2 + [p] + SuM([ab]) * 9 + AVG(
[a] ).
>>I changed the RegEx as below to include decimal numbers as
[totalChrgs]
+ 2.3 * 5.67. The RegEx is as below.
>>^([0-9]+(\.\d{2})?|\[[a-zA-z]+([0-9])*\]|([Ss][Uu][Mm]|[Aa][Vv][Gg]|
[Cc][Oo][Uu][Nn][Tt])\([ ]*([0-9]+(\.\d{2})?|\[[a-zA-z]+([0-9])*\])[
]*\))([ ]*[-+*/][
]*([0-9]+(\.\d{2})?|\[[a-zA-z]+([0-9])*\]|([Ss][Uu]
[Mm]|[Aa][Vv][Gg]|[Cc][Oo][Uu][Nn][Tt])\([
]*([0-9]+(\.\d{2})?|\[[a-zA-
z]+([0-9])*\])[
]*\)))*$
But it is not matching with the expression. What could be the
problem?

Reply soon,

Thanks and regards,
Venu
Change \.\d{2} in \.\d{1,} or \.\d{1,2} to allow one or more
number(s) after
the decimal point. Currently the regex only matches if there are
exactly
2 numbers after the point.
Also consider rewriting \d as [0-9], I find it more readable and it's
one of the few times I make an exclusion to the rule mentioned below.

Also note that you can rewrite this:
[a-zA-z]+([0-9])*
as

[a-zA-z]+[0-9]* (I usually say that in case of a regex, shorter is
better).

Jesse

--
Jesse Houwing
jesse.houwing at sogeti.nl
Hi Jesse, how are you doing?
How can we incorporate an expression like this in our regular
expression?
((([col1]+[col2])*[col3])/5)
Thanks,
Venu

You can, but it isn't easy. There is a story on CodeProject which explains
this rather well:

http://www.codeproject.com/KB/recipe..._Grouping.aspx

There's also a whole chapter for balanced groups in the book by Dan Appleman,
which is only available as a ebook download from amazon at the moment:

http://www.amazon.com/Regular-Expres.../dp/B0000632ZU

--
Jesse Houwing
jesse.houwing at sogeti.nl
Jan 11 '08 #11

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

Similar topics

6
by: paulsmith5 | last post by:
Hi, I have the following regular expression to validate a date-time field in European or d/m/y h:m:s format. ...
8
by: Rajeev Soni | last post by:
Hi I am looking for the regular expression for validating the allowed file types to upload like files like "zip,pdf,doc,rtf,gif,jpg,png,txt"; and the expression should not be case sensitive like...
3
by: Mark | last post by:
To validate the length of a multiline textbox, I'm told that I have to use a regular expression validator. The regular expression below limits it to 25 characters in length, but if the user enters...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
14
by: olekristianvillabo | last post by:
I have a regular expression that is approximately 100k bytes. (It is basically a list of all known norwegian postal numbers and the corresponding place with | in between. I know this is not the...
7
by: Tizzah | last post by:
What is wrong with that? regex = /^(http|https):\/\/+({1}+)*\.{2,5}(({1,5})?\/.*)?$/ if(field.hpage.value != regex.test(field.hpage.value)){ alert("Bad Homepage") field.hpage.focus()...
1
by: durga2005 | last post by:
hi I m validating a textbox using regular expression validator and these controls are placed inside the update panel the validation is not working inside update panel
1
by: durga2005 | last post by:
hi i have a textbox and regular expression validator control .i have placed these control inside update panel. just im validating the textbox with regular expression validator control when i...
7
by: graphicsxp | last post by:
Hi, I can't figure out what the regular expression would look like for validating a string such as : Lastname, Firstname I could only come up with /\w/ which doesn't check for the comma. ...
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.