NetBeans replace all constants using regex

I am using NetBeans and I want to know what regex to use to add single / double quotes around each constant. Each constant is defined as follows:

define(SYSTEM_BASEDIR, '/base/dir');

      

Afaik, this is not the right way. I need to convert all constants to this:

define('SYSTEM_BASEDIR', '/base/dir');

      

Thanks in advance to all the helpers!

+3


source to share


6 answers


You are correct, which define(SYSTEM_BASEDIR, '/base/dir');

is invalid syntax, since you are using a constant before you define it.

Now for the regex:

Open the Replace dialog box ( Ctrl+ H)

Find what: define\((\w*),

Replace with: define("$1",



This will do the following:

define(BLA,"test");

      

in

define("BLA","test");

      

+6


source


Netbeans Ctrl

+H

find: (define\()(\w*)(\,)
replace: define("$2",

      



check regex

+3


source


$result = preg_replace('/\bdefine\((\w+),/', 'define(\'\1\',', $subject);

      

changes all instances

define(<alphanumeric word>,

      

in

define('<alphanumeric word>',

      

+1


source


Netbeans Ctrl+H

find: define\(([A-Za-z_]+),
replace: define('$1',

      

check regex

+1


source


From your editor find the replacement text

use this reg expression here:

find : define\((.*),

replace : define('\$1',

      

If you are using notepad ++

replace : define('\1', 

      

0


source


replace with this regex

(?<constant>(?:[A-Z]+(_[A-Z]+)*))

      

0


source







All Articles