Skip to content

Instantly share code, notes, and snippets.

@gunjanpatel
Last active December 30, 2015 09:00
Show Gist options
  • Save gunjanpatel/5501981 to your computer and use it in GitHub Desktop.
Save gunjanpatel/5501981 to your computer and use it in GitHub Desktop.
Use full Regular Expression with redSHOP using Sublime Text 2 or 3 and PhpStorm

Find for loop for Code Style improvement by calculate the length of the loop in advance

Target: for ($i = 0; $i < count($columns); $i++)

Search: \(((\$\w) = \d); \$\w\s<\s(count\(\$(\w+)\)); (\$\w\+\+)\)

Replace: ($1, $2n = $3; $2 < $2n; $5)

Get string between

function findStringBetween($start, $end, $string) 
{
    preg_match_all('/' . preg_quote($start, '/') . '([^\.)]+)'. preg_quote($end, '/').'/i', $string, $m);
    return $m[1];
}

$start   = "{product_attribute_loop_start}";
$end     = "{product_attribute_loop_end}";
$matches = $this->findStringBetween($start, $end, $template);  

Get template between product loop start and end

\{product_loop_start\}(.*)\{product_loop_end\}

\{product_loop_start\}(((?!\{product_loop_start\}\{product_loop_end\}).)+)\{product_loop_end\}

require_once matching

In PHPStorm or Sublime Text2 or 3 search box you add:

require_once(\s)*\((.*)\);

And replace it for:

require_once $2;

Another usefull regex

Replace array into Object:

Target: foo['xyz']

Search : foo(\[\'(.*)\'\])

Replace : foo->$2

Replace joomla assignRef to $this:

Target: $this->assignRef('foo', $foo)

Search: \$this->assignRef\('(.*)', (.*)\)

Replace: $this->$1 = $2

Remove space from array assignent

Target: $array ['foo']

Search: (\$.*) (\[(.*)\])

Replace: $1$2

Instancing New class without parentheses

Target: new EasyBlogModelBlogs();

Output: new EasyBlogModelBlogs;

Search: (new (?!Array|Object|Option|XMLHttpRequest)[a-zA-Z_]*)\(\);

Replace: $1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment