I am wanting to remove the icons from the h1 title element in opencart admin panel. I'm trying to use an asterisk as a wildcard for the file name, but it's not working out.
The docs says the search data:
<h1><img src="view/image/*.png" alt="" /> <?php echo $heading_title; ?></h1>
should be a valid regex pattern, though I'm not familiar with regex. How can I do this correctly in vqmod?
<file name="admin/view/template/*/*.tpl">
<operation>
<search regex="true" position="replace"><![CDATA[
<h1><img src="view/image/*.png" alt="" /> <?php echo $heading_title; ?></h1>
]]></search>
<add><![CDATA[
<h1><?php echo $heading_title; ?></h1>
]]></add>
</operation>
</file>
In vQmod, the regex still needs to have its delimiters. You are also better off just using a generic search for the <h1> since you are setting it to just the heading title.
<file name="admin/view/template/*/*.tpl">
<operation>
<search regex="true" position="replace"><![CDATA[~<h1>.*?</h1>~]]></search>
<add><![CDATA[<h1><?php echo $heading_title; ?></h1>]]></add>
</operation>
</file>
In regex, an asterisk * is a quantifier which means match zero or more times.
I think you want to match anything, one or more times. You do that with .+. Ofcourse you want it ungreedy, so the final pattern is .+?.
. : match anything
+ : a quantifier which means match one or more times
? : + followed by ? means to match ungreedy
Let's apply the above in the code:
<h1><img src="view/image/.+?\.png" alt="" /> <?php echo preg_quote($heading_title); ?></h1>
We need to escape the dot in \.png
We'll use preg_quote() to escape properly regex reserved characters in the $heading_title variable
Related
I have text in many html files that is in this format:
<!-- BEGIN FOOTER -->
<div id="footer">
<p align="right"> Slogan<br />
5555 Street East <br />
City, State 99999 <br />
Call Us (555)555-5555 <br />
</p>
<div align="center">
<a class="footer" href="http://www.example.com" title="Site">Site</a>
</div>
<br>
</div>
<!--END FOOTER-->
I am using this:
sed -E -i 's/(<!-- BEGIN FOOTER -->)(.|\n)*(<!--END FOOTER-->)/\1 <br>REPLACE<br> \3 /m' file.html
but not working to capture & backreference them:
\1 <!-- BEGIN FOOTER -->
\3 <!--END FOOTER-->
And insert this in between them:
REPLACE
So trying to end up with this:
<!-- BEGIN FOOTER -->
<br>REPLACE<br>
<!--END FOOTER-->
This might work for you (GNU sed):
sed '/<!-- BEGIN FOOTER -->/{:a;N;/<!--END FOOTER-->/!ba;s/\n.*\n/\n<br>REPLACE<br>\n/}' file
This gathers up lines between footers and replaces the lines between with the required string.
An alternative (similar to revo);
sed '/<!-- BEGIN FOOTER -->/,/<!--END FOOTER-->/!b;/<!-- BEGIN FOOTER -->/b;/<!--END FOOTER-->/!d;i\<br>REPLACE<br>' file
Another way:
sed '/<!-- BEGIN FOOTER -->/,/<!--END FOOTER-->/!b;/<!--END FOOTER-->/p | sed '/<!-- BEGIN FOOTER -->/p;/<!-- BEGIN FOOTER -->/,/<!--END FOOTER-->/c\<br>REPLACE<br>'
sed reads from input file one line at a time and directs the result to standard output. It means no where in input line there is \n character to be matched except in some cases that a few special commands are being used. You could use address ranges along with insert i command to achieve desired output:
sed '/BEGIN FOOTER/,/END FOOTER/{ /END FOOTER/{i\<br>REPLACE<br>
b}; /BEGIN FOOTER/b; d;}' file
Watch the linebreak after first line. i inserts data before current line in pattern space. b jumps over remaining commands causing a new iteration to be dobe. /BEGIN FOOTER/,/END FOOTER/ implies a range in which the other commands should execute.
You can first save the lines with BEGIN FOOTER and END FOOTER in beg and end variables:
beg=$(grep -n "BEGIN FOOTER" inputfile | cut -d: -f1)
end=$(grep -n "END FOOTER" inputfile| cut -d: -f1)
Then use sed's c\ command:
sed -i.bak "$((beg+1)),$((end-1))c\<br>REPLACE<br>" inputfile
Result:
<!-- BEGIN FOOTER -->
<br>REPLACE<br>
<!--END FOOTER-->
Alternatively use the single command:
sed "/BEGIN FOO/,/END FOO/c\<!--BEGIN FOOTER-->\n<br>REPLACE<br>\n<!--END FOOTER-->" inputfile
I am trying to find everything from one div to the start of another and include everything in between, even if there is a line break and even if there is other tags and php functions in between.
I want it to start the search at <div="constant-strip"> and end on <?php include....
and i want it to delete everything inside the and everything that comes after <div="constant-strip"> until it reaches the <?php include
even though there are other <?php and <div> tags between those.
I have searched everywhere, but all the regex and wildcard etc. searches i can find, people want to stop at the end of the div and don't include divs that are inside it or only apply to text etc...
all the ([^<]) and i've tried ([\s\S])+ and all those, but none of them work
basically i want to change this:
<div id="constant_strip" class="clearfix">
<div class="clearfix"><a href="<?php echo $division ?>_brands.php">
<img src="images/people.png" width="22" height="21" style="<?php echo $stripColour ?>" />View our suppliers</a></div>
<div id="call">Call us: 021 323 4088</div>
</div>
</div>
<?php include('/footer.php'); ?>
and turn it into just this: <?php include('/footer.php'); ?>
the problem is that it doesn't have exactly the same information on every page
The following regex will match the middle part, you want to replace:
(?<=<div id="constant_strip" class="clearfix">)[\s\S]*?(?=<\?php include)
I`m trying to replace a chunk of code on the model with custom code, that I wrote.
Here is the code. I works, but it leaves a lot of offset.
Maybe there is a better way to do this
<operation info="Example of the vQmod">
<search position="replace" offset="3"><![CDATA[
Some code I want to Replace
Some code I want to Replace
Some code I want to Replace
]]></search>
<add><![CDATA[
Replaced Code
Replaced Code
Replaced Code
]]></add>
</operation>
Vqmods offset value is for replacing a line and the following x lines, however the search is for one line only. Vqmod doesn't match multiple lines in search.
Example :
Input
public function index() {
$a = rand();
$b = rand();
if ($a == $b) {
echo 'oh noes';
return false;
}
}
Script
<?xml version="1.0" encoding="UTF-8"?>
<modification>
<id>Replace many lines with one</id>
<version>1.0</version>
<vqmver>2.X</vqmver>
<author>xxx</author>
<file name="path/to/testfile.php">
<operation info="Replace index function">
<search position="replace" offset="7"><![CDATA[
public function index() {
]]></search>
<add><![CDATA[
public function index($arr = array()) {
foreach ($arr as $a) {
echo $a;
}
}
]]></add>
</operation>
</file>
</modification>
Output
public function index($arr = array()) {
foreach ($arr as $a) {
echo $a;
}
}
Note : There are still 7 blank lines. The offset clears the extra 7 lines of code from the input, but the replaced code is added in place of the initial line. So there will be 7 extra spaces after the new code, but it will not affect the code functionality, only the look of the vqcache file which is of no importance.
In Opencart, you cannot search for multiple lines of code and replace it with new multiple lines of codes. It can only search a single line and then replace or add with single line or multiple lines of code.
Offset is to search a single line of code and then offset the number of lines below and then replace or add new coding. Something like this:
<operation info="Example of the vQmod">
<search position="replace" offset="3"><![CDATA[
code I want to Replace at offset line 3
]]></search>
<add><![CDATA[
Replaced Code
add code
add code
]]></add>
</operation>
I am working on web-project with several languages: each HTML text inside a tag must be wrapped inside a <?php echo _("..."); ?> so :
<div>My text</div> transforms into <div><?php echo _("My text"); ?></div>
The fact is I want to track the huge amount of these occurrences of text in order to transform it into texts wrapped by a 'php echo'?. Does it exist a regex to track these occurrences?
I have a project that includes 49 folders, each one has a file called index.php
All index.php files are almost the same except for one part that changes depending on the folder it is in.
<?php include_once("/home/bgarch/public_html/galleryheader.html"); ?>
<?php include_once("/home/bgarch/public_html/culture/loadscripts.html"); ?>
</head>
<body>
<div class="header">
<?php include_once("/home/bgarch/public_html/header.html"); ?>
</div>
<div class="clear"></div>
<div class="displaywrapper">
<?php include_once("content.html"); ?>
</div></div>
<div class="clear"></div>
<?php include_once("/home/bgarch/public_html/footer.html"); ?>
In the second line where the above reads: "../culture/.." the word culture is the variable and is different based on the folder it is in.
What I need to do know is do a "Find/Replace all in project" that automatically replaces all the text inside each 'index.php' file with the following"
<?php include_once("http://www.bgarchitect.co.nz/subPage/index.php"); ?>
I have spent the past 2 hours trying to figure out regular expressions to acomplish this but have been unsuccessful so far.
Maybe it is not possible to do so?
Anyway, I thought I'd ask a question here in hopes it is in fact much easier than I anticipated. So any help/pointer/hints or tricks are much appreciated.
Thanks for reading,
Jannis
If I understood right, you want to replace the word culture (which is the current directory) with the word subPage?
You can do this with the help of TextMate bundles.
Bundles > Bundle editor > Edit commands, than add a New command.
Add this as a command. I think it does what you want. You have to set the input to the command as Entire document and the output to Replace document.
#!/bin/bash
sed "s/"${TM_DIRECTORY##*/}"/theWordYouWanToReplaceTheDirWith/g" | cat