[ale] Regular Expression.

David Tomaschik ozone at webgroup.org
Tue Sep 4 13:21:34 EDT 2007


Michael B. Trausch wrote:
> For the life of me, I cannot figure out a regex that will do what I want
> it to do.  I want to change every instance of the string:
>
> 	$_GET['varname']
>
> to:
>
> 	get_get('varname')
>
> Using something like sed to automagically do the work for me.  I tried
> to do this, however, using the following regex:
>
> 	's/$_GET\[\('.*'\)\]/get_get(\1)/g;'
>
> ... which only works if there is one $_GET[''] on the line.  If there
> are more than one, though, it does something like this:
>
> if ((isset(get_get('id'])) && ($_GET['id') != ''))
>
> Is there a way to make the \[\('.*'\)\] part of the regex less greedy so
> that it will match EXACTLY one instance?  What follows may be any
> character, including a newline.
>
> 	-- Mike
>
>   
> ------------------------------------------------------------------------
>
>   
Try something like:

's/$_GET\[\('[A-Za-z0-9_-]*'\)\]/get_get(\1)/g'

David



More information about the Ale mailing list