Jump to content

Dynamically Content-Aware Regular Expressions?


MrFish

Recommended Posts

I'm writing a script to push out config file updates to a number of sites. In the configuration some site specific information shouldn't change like db username and passwords. Here is a sample-

<?php	    // #Mobile Sniffer         ... 	    // ~Mobile Sniffer 	    // #Constants	    // #host	    define("HOST", "");	    // ~host	    // #user	    define("USER", "");	    // ~user	    // #pass	    define("PASS", "");	    // ~pass	    // #db	    define("DB", "");	    // ~db	    // #wysiwyg	    define("WYSIWYG", false);	    // ~wysiwyg	    // #paths	           ...	    // ~paths 	    // #Courtesy Connect	    mysql_connect(HOST, USER, PASS) or die(mysql_error());	    mysql_select_db(DB) or die(mysql_error());	    // ~Courtesy Connect 	    // #Dependencies Load	    require_once(__BASEADMINPATH__."bin/loaddependencies.php");	    // ~Dependencies Load?>

So to do what I'm thinking I've split everything into chunks. A chunk starts with # followed by the name of the chunk and ends with ~ followed by the name of the chunk. Some chunks are nested- they don't have to be but I'd like to organize it better. You can see the problem with a regex that looks like this- |\/\/ #(.*)([\w\W\d\s]+)\/\/ ~(.*)|U This would pull this chunk- // #Constants// #hostdefine("HOST", "");// ~host So what I'd like to be able to do is something like this- |\/\/ #(.*)([\w\W\d\s]+)\/\/ ~$1|U Where the regex would use the first match as an identifier for the closing tag ($1). But I can't find any examples of this. Is it possible?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...