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

V

venugopal.sjce

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.
 
J

Jesse Houwing

Hello (e-mail address removed),
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...s=org.mozilla:en-US:official&client=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 :)
 
V

venugopal.sjce

Hello (e-mail address removed),




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+mppg&ie=utf-8&oe=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..
 
J

Jesse Houwing

Hello (e-mail address removed),
Hello (e-mail address removed),
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+mppg&ie=utf-8&oe=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 :)
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 ;)
 
V

venugopal.sjce

Hello (e-mail address removed),




On Nov 6, 2:53 pm, Jesse Houwing <[email protected]>
wrote:
Hello (e-mail address removed),
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+mppg&ie=utf-8&oe=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 :)
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
 
J

Jesse Houwing

Hello (e-mail address removed),
Hello (e-mail address removed),
On Nov 6, 2:53 pm, Jesse Houwing <[email protected]>
wrote:

Hello (e-mail address removed),

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+mppg&ie=utf-8&oe=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 ;)
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 :).
 
V

Venu

Hello (e-mail address removed),




On Nov 6, 4:51 pm, Jesse Houwing <[email protected]>
wrote:
Hello (e-mail address removed),
On Nov 6, 2:53 pm, Jesse Houwing <[email protected]>
wrote:
Hello (e-mail address removed),
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+mppg&ie=utf-8&oe=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 ;)
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
 
J

Jesse Houwing

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
 
J

Jesse Houwing

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
 
V

Venu

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

Hi Jesse, how are you doing?
How can we incorporate an expression like this in our regular
expression?
((([col1]+[col2])*[col3])/5)

Thanks,
Venu
 
J

Jesse Houwing

Hello Venu,
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
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/recipes/RegEx_Balanced_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-Expressions-NET-Dan-Appleman/dp/B0000632ZU
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top