Discussion:
Replace in project with regex
Maxime
2009-07-07 14:34:03 UTC
Permalink
Hello,



Is it possible (and how i can do it) to use regex for replacement ?



An example with php: in order to become "php 5.3 guidelines", i've to replace:

session_register('my_var')

by:

$_SESSION('my_var')



Of course i'm a lazy guy and i'd like to replace all session_register(*) by $_SESSION(*) into my project with one click.



I found with this [^_]session_register\((.)*\)

but replacement seems to not use regular expression :(



Any idea how i can to that ?

Thanks for your help.
Marc Farrow
2009-07-07 14:44:35 UTC
Permalink
on the replace dialog, there is a checkbox for "REGEX"
Post by Maxime
Hello,
Is it possible (and how i can do it) to use regex for replacement ?
session_register('my_var')
$_SESSION('my_var')
Of course i'm a lazy guy and i'd like to replace all session_register(*) by
$_SESSION(*) into my project with one click.
I found with this [^_]session_register\((.)*\)
but replacement seems to not use regular expression :(
Any idea how i can to that ?
Thanks for your help.
Maxime
2009-07-07 15:02:21 UTC
Permalink
I found it and checked it, but regex is working only onto search string, not replace string.

with this:

[^_]session_register\((.)*\) as search string

\$_SESSION\((.)*\) as replace string



Example:


Code:
session_register('my_var');





Become:


Code:
$_SESSION((.)*);



instead of $_SESSION('my_var')
arittner
2009-07-07 15:07:56 UTC
Permalink
Hi!



Each group placeholder is $1, $2, $3 not a star.



http://www.netbeans.org/kb/articles/netbeans-hacks-1.html#eol



But I've no idea if it works in the project search&replace.



hth and br, josh.

------------------------
JNBB/BeanDev: Das deutsche Blog zur NetBeans Platform (http://www.sepix.de/blogs/blogrittner)
Maxime
2009-07-07 15:20:53 UTC
Permalink
It helps me thanks, but i still can't do it.

$0 includes "session_register"

$1 gives me only one character of 'my_var' ...
Peter B. West
2009-07-13 01:14:26 UTC
Permalink
That's because your sub-expression only selects one character at a time.

You need (.*) rather than (.)*
Post by Maxime
It helps me thanks, but i still can't do it.
$0 includes "session_register"
$1 gives me only one character of 'my_var' ...
arittner
2009-07-07 15:25:10 UTC
Permalink
Hi!



Sure, your regex doesn't fit.



[^_]session_register\((.)*\)



$0 is the complete search result.



$1 is (.) <- one character



Please test it with:



[^_]session_register\((.*?)\)



$1 should now (.*?)



hth, josh.

------------------------
JNBB/BeanDev: Das deutsche Blog zur NetBeans Platform (http://www.sepix.de/blogs/blogrittner)
arittner
2009-07-07 16:53:23 UTC
Permalink
Hi!



[ ] is a group of characters. ^ negates the group. The meaning of [^_] is NOT UNDERSCORE (IMHO you don't need this part)



br, josh.

------------------------
JNBB/BeanDev: Das deutsche Blog zur NetBeans Platform (http://www.sepix.de/blogs/blogrittner)
Maxime
2009-07-08 06:40:55 UTC
Permalink
Thanks for help
Loading...