Home Download Buy Blog Forum Support

RegReplace Plugin

Re: RegReplace Plugin

Postby facelessuser on Tue Aug 20, 2013 12:27 am

RegReplace uses the python re engine (mainly because the ST find API is very awkward for RegReplace to access due to the way RegReplace works, and I didn't want to use the ST API in half of the code, and re in the other half).

vitaLee wrote:I have the following usecase:
find hex colors with uppercase letters: #([A-F\d]+)
replace uppercase letters with lower ones: #\L$1\E


RegReplace, since it uses re, requires groups to be specified as \1 not $1. So, #\L\1\E would be more appropriate (in a string you would obviously escape the slashes).

But you still won't get your desired effect because re does not support Oniguruma.

I can see the desire to use Oniguruma though...maybe down the line I can implement this with a third party package like https://github.com/mitsuhiko/ponyguruma, or at the very least create some kind of system to allow users to write scripts to manipulate the regex groups format on replace.

Hopefully, that answered your questions, and while I don't have an immediate fix to allow you to do what you want, maybe down the line. Feel free to make this suggestion on Github at the RegReplace repo.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: RegReplace Plugin

Postby vitaLee on Tue Aug 20, 2013 7:49 am

I guessed that could be the reason for this.
Thanks anyway.
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm

Re: RegReplace Plugin

Postby Stepharr on Thu Nov 07, 2013 7:01 pm

What are my options for running a RegReplace replacement on a batch of 360 files?
Stepharr
 
Posts: 1
Joined: Thu Nov 07, 2013 6:58 pm

Re: RegReplace Plugin

Postby facelessuser on Thu Nov 07, 2013 8:34 pm

Stepharr wrote:What are my options for running a RegReplace replacement on a batch of 360 files?

Right now? Probably something like sublimes built in batch find/replace, or some other kind of batch search and replace tool, I use grepWin on windows.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: RegReplace Plugin

Postby BUGMENOT! on Wed Apr 09, 2014 5:20 pm

Hi, I hope 'facelessuser' can answer me this:

i'm trying to use this snippet:
Code: Select all
// busca consultas SQL y las encierra en query("consulta")
        "wrap_sql_in_query": {
            "scope": "sql",
            "find" : "((\"|')(delete|select|insert|update)\\s+[\\w\\s=,.'\\$;\\(\\)+-<>|]+(\"|'))",
            "replace": "query(\\1)",
            "greedy_replace": true,
            "case" : false
        },


I have that in /home/user/.config/sublime-text-2/Packages/RegReplace/reg_replace.sublime-settings

in /home/user/.config/sublime-text-2/Packages/RegReplace/Default.sublime-commands

i have:
Code: Select all
        {
      "caption": "Reg Replace: Update PG to ADODB",
      "command": "reg_replace",
      "args": {"replacements": ["wrap_sql_in_query", "update_pg_to_adodb", "update_pg_to_adodb1", "update_pg_result", "comment_pg_exec"], "find_only": true}
   },


but no results are highlighted, i tested the regex in both http://www.pythonregex.com/ and https://pythex.org/ and it worked fine (removing the escape \)

the test case is:
Code: Select all
$consulta    = "select consdocdeu,fechacompro from compromi where estado ='A' and fechacompro <= date(now()) -1  ";


and the expected result is:

Code: Select all
$consulta    = query("select consdocdeu,fechacompro from compromi where estado ='A' and fechacompro <= date(now()) -1  ");



is like the backslashes aren't working, but if i remove the backslashes sublime tells:

Error trying to parse settings: Invalid escape in ~/.config/sublime-text-2/Packages/RegReplace/reg_replace.sublime-settings:92:22


thank you!
BUGMENOT!
 
Posts: 18
Joined: Thu Sep 19, 2013 1:54 pm

Re: RegReplace Plugin

Postby facelessuser on Wed Apr 09, 2014 5:57 pm

What language (syntax) is your code in?
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: RegReplace Plugin

Postby facelessuser on Wed Apr 09, 2014 6:06 pm

I threw this in PHP real quick.

Notice I removed the "sql" scope, because at least in PHP, the string did not scope to "sql".

        // busca consultas SQL y las encierra en query("consulta")
"wrap_sql_in_query": {
// "scope": "sql",
"find" : "((\"|')(delete|select|insert|update)\\s+[\\w\\s=,.'\\$;\\(\\)+-<>|]+(\"|'))",
"replace": "query(\\1)",
"greedy_replace": true,
"case" : false
},


You didn't provide me with the other commands, so I reformatted the command to only call the wrap command you gave me.

    {
"caption": "Reg Replace: Wrap SQL Query",
"command": "reg_replace",
"args": {"replacements": ["wrap_sql_in_query"], "find_only": true}
},


It turned this:

<?

$consulta = "select consdocdeu,fechacompro from compromi where estado ='A' and fechacompro <= date(now()) -1 ";

?>


To this just fine:

<?

$consulta = query("select consdocdeu,fechacompro from compromi where estado ='A' and fechacompro <= date(now()) -1 ");

?>



Maybe removing the scope is all you need to do? Maybe there is something wrong with the additional commands you did not provide me with? I don't know since you did not provide me enough information. But there is nothing wrong with the regex, and since I don't know what syntax language you are using, I cannot be sure whether the sql scope requirement is helpful or not, but it is a hindrance in stock PHP.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: RegReplace Plugin

Postby BUGMENOT! on Wed Apr 09, 2014 6:12 pm

is php
BUGMENOT!
 
Posts: 18
Joined: Thu Sep 19, 2013 1:54 pm

Re: RegReplace Plugin

Postby BUGMENOT! on Wed Apr 09, 2014 6:14 pm

Removing the scope did the trick!,
thank you and excellent plugin, i though scope mean 'group these regex' its the scope mean for file types??

thank you again

facelessuser wrote:I threw this in PHP real quick.

Notice I removed the "sql" scope, because at least in PHP, the string did not scope to "sql".

        // busca consultas SQL y las encierra en query("consulta")
"wrap_sql_in_query": {
// "scope": "sql",
"find" : "((\"|')(delete|select|insert|update)\\s+[\\w\\s=,.'\\$;\\(\\)+-<>|]+(\"|'))",
"replace": "query(\\1)",
"greedy_replace": true,
"case" : false
},


You didn't provide me with the other commands, so I reformatted the command to only call the wrap command you gave me.

    {
"caption": "Reg Replace: Wrap SQL Query",
"command": "reg_replace",
"args": {"replacements": ["wrap_sql_in_query"], "find_only": true}
},


It turned this:

<?

$consulta = "select consdocdeu,fechacompro from compromi where estado ='A' and fechacompro <= date(now()) -1 ";

?>


To this just fine:

<?

$consulta = query("select consdocdeu,fechacompro from compromi where estado ='A' and fechacompro <= date(now()) -1 ");

?>



Maybe removing the scope is all you need to do? Maybe there is something wrong with the additional commands you did not provide me with? I don't know since you did not provide me enough information. But there is nothing wrong with the regex, and since I don't know what syntax language you are using, I cannot be sure whether the sql scope requirement is helpful or not, but it is a hindrance in stock PHP.
BUGMENOT!
 
Posts: 18
Joined: Thu Sep 19, 2013 1:54 pm

Re: RegReplace Plugin

Postby facelessuser on Wed Apr 09, 2014 6:55 pm

BUGMENOT! wrote:i though scope mean 'group these regex' its the scope mean for file types??

It applies to the highlight scoping. For instance, if you want the regex to only be applied to "strings", you set the scope as "string". Then RegReplace finds all of the parts of your file that are of the "string" scope, and applies the regex to them individually.

Like if I want to target strings for changing their quote style:

        // Swap quotes
"swap_quotes_to_single": {
"scope": "string",
"find" : "^\"(.*?)\"$",
"replace": "'\\1'",
"greedy_replace": false
},
"escape_single_quotes": {
"scope": "string",
"find" : "^(\".*?(?<!\\\\))((?:[\\\\]{2})*)'(.*?\")$",
"replace": "\\1\\2\\'\\3",
"greedy_replace": false,
"multi_pass_regex": true
},
"unescape_double_quotes": {
"scope": "string",
"find" : "^('.*?(?<!\\\\))((?:[\\\\]{2})*)\\\\\"(.*?')$",
"replace": "\\1\\2\"\\3",
"greedy_replace": false,
"multi_pass_regex": true
},


    // Flip Quotes
{
"caption": "Replace: Swap Quotes to Single",
"command": "reg_replace",
"args": {"replacements": ["escape_single_quotes", "swap_quotes_to_single", "unescape_double_quotes"], "find_only": true}
},


etc.

Hope that helps.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

PreviousNext

Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 5 guests