开发者

Regexp to parse expression

I am developing an utility app in VB6 for my use to parse code and extract all the expression leaving the code semantic. At first I am focusing on PHP and VB6.

For example, if I pas开发者_Python百科s this code in PHP:

if($myvar ==0 || $myvar < 0){

echo "$myvar is less that 0";
}

The regular expression should be able to give me just two lines $myvar == 0 || $myvar < 0 and echo "$myvar is less that 0";.

[EDIT]

Although there might be nested ifs, i also want to parse it, displaying it in the result that it was nested.

Also i want it to parfse functions too

public function myfoo($somevar,$myvar,$yourvar){

$temvar= $somevar*2
$temvar= convertToString($myvar,$yourvar)
return $temvar

}

in this case it will extract myfoo($somevar,$myvar,$yourvar) $temvar= $somevar*2 $temvar= convertToString($myvar,$yourvar) return $temvar

Two questions

  1. How do I figure out regexp to parse such text?
  2. Is there any free library that can do this?


Check radsoftware.com.au for their very handy regular expression tester

check out http://www.regular-expressions.info/vb.html for info about handling regular expressions in a VB6 app (VB6 doesn't have native regex capability like.net)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜