The Artima Developer Community
Sponsored Link

PHP Buzz Forum
Regex guru needed

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Tobias Schlitt

Posts: 120
Nickname: dotxp
Registered: Sep, 2004

Tobias Schlitt is a geek, highly addicted to PHP.
Regex guru needed Posted: Nov 13, 2004 10:22 AM
Reply to this message Reply

This post originated from an RSS feed registered with PHP Buzz by Tobias Schlitt.
Original Post: Regex guru needed
Feed Title: Tobias Schlitt - Weblog
Feed URL: http://php-applications.de/lists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundlists/listinfo/phpug-dortmundapplications/blog/rss.php?category=2_PHP&version=0.91
Feed Description: a passion for php
Latest PHP Buzz Posts
Latest PHP Buzz Posts by Tobias Schlitt
Latest Posts From Tobias Schlitt - Weblog

Advertisement

I recently wanted to extract all function/method prototypes from a PHP files, using PCRE. The extraction itself is not a real problem, but for further processing I need every single parameter of each function as a seperate element. Surely it would be no problem, when using 2 regex (a. extract the function prototype, b. extract the parameters), but this would (IMHO) be much more resource intensive than doing all at once.

Here is a (much smaller than the real one) example which describes the problem (see the extended entry for the real regex I developed):


<?php
$string = "(aaa bbb ccc ddd)";
$regex = "/\((?:
                ([a-z]+)\s*
             )+\)/x";
preg_match($regex, $string, $matches);
?>

The output of a var_dump($matches) looks like this:

array(2) {
  [0]=>
  string(17) "(aaa bbb ccc ddd)"
  [1]=>
  string(3) "ddd"
}

Where I would expect something like

array(5) {
  [0]=>
  string(17) "(aaa bbb ccc ddd)"
  [1]=>
  string(3) "aaa"
  [2]=>
  string(3) "bbb"
  [3]=>
  string(3) "ccc"
  [4]=>
  string(3) "ddd"
}

or

array(2) {
  [0]=>
  string(17) "(aaa bbb ccc ddd)"
  [1]=> 
  array(4) {
     [0]=>
     string(3) "aaa"
     [1]=>
     string(3) "bbb"
     [2]=>
     string(3) "ccc"
     [3]=>
     string(3) "ddd"
   }
}

Does anyone know a solution for that (I repeate, in 1 regular expression)?


Continue reading "Regex guru needed"

Read: Regex guru needed

Topic: 22 pat en Français (pat goes french) 13 Previous Topic   Next Topic Topic: Election Reflection 2e

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use