Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex help

Status
Not open for further replies.

apertosa

Programmer
Aug 11, 2006
15
US
Hi, hope some of you Perl folks might be able to help

Problem:
I have a string that contains an expression.

An expression can be: one or more variables, one or more operators, another variable (or number).

So my expression looks like this (for example):

-20.0 * pvs_variable1 + pvs_variable2

Note that I do not know how many operands and operators the expression contains.

I need to be able to extract the operands and the operators of the expression, however many there might be.

How can I do this?

Thanks for your help.
 
What have you tried thus far?

Is there any reason that a simple split can't accomplish what you want? In other words, is the data always spaced judiciously?

Code:
[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$expression[/blue] = [red]'[/red][purple]-20.0 * pvs_variable1 + pvs_variable2[/purple][red]'[/red][red];[/red]

[black][b]my[/b][/black] [blue]@components[/blue] = [url=http://perldoc.perl.org/functions/split.html][black][b]split[/b][/black][/url] [red]'[/red][purple] [/purple][red]'[/red], [blue]$expression[/blue][red];[/red]

[url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] [url=http://perldoc.perl.org/functions/join.html][black][b]join[/b][/black][/url] [red]'[/red][purple],[/purple][red]'[/red], [blue]@components[/blue][red];[/red]

- M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top