Gossamer Forum
Home : General : Perl Programming :

Help! Regexp needed!

Quote Reply
Help! Regexp needed!
Hi there,

i need a regexp to validate formulars like "$a + min($b, $c, $e)"

Please help!

Quote Reply
Re: [mash4077] Help! Regexp needed! In reply to
The regex needed depends on how the formula is laid out and whether you want to capture anything.

If it is in that same format everytime and you don't want to capture specific parts then sometime like this should work:

if ($string =~ m!
\$[a-z] # Something like $a or $b etc.
\s* # Optional space.
[+/\*%-] # Multiplication, addition, subtraction etc...
\s* # Optional space.
[a-z]+ # cos, sin, min etc.
\( # Argument bracket.
[a-z\$,\s]+ # Arguments such as $a, $b, $c etc.
\) # Closing argument bracket.
!xsg) {
print "Got a match!\n";