Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <a href="http://www.regular-expressions.info/lookaround.html" rel="nofollow">lookaround</a> syntax to match <code>?cid=something</code> preceded by the URL and followed by a <code>'</code></p> <p>This pattern should work:</p> <pre><code>(?&lt;=\Qhttps://www.mydomain.com/shop/bags\E)\?cid=[^']++(?=') </code></pre> <p>If you replace that pattern with your replacement then the entire bit from <code>?cid</code> until <code>'</code> will be replaced.</p> <p>Here is an example in Java (ignore the slightly different syntax):</p> <pre><code>public static void main(String[] args) { final String[] in = { "onclick=\"location.href='https://www.mydomain.com/shop/bags?cid=Black'", "onclick=\"location.href='https://www.mydomain.com/shop/bags?cid=Beige'", "onclick=\"location.href='https://www.mydomain.com/shop/bags?cid=Green'" }; final Pattern pattern = Pattern.compile("(?&lt;=\\Qhttps://www.mydomain.com/shop/bags\\E)\\?cid=[^']++(?=')"); for(final String string : in) { final Matcher m = pattern.matcher(string); final String replaced = m.replaceAll("SOMETHING_ELSE"); System.out.println(replaced); } } </code></pre> <p>Output</p> <pre><code>onclick="location.href='https://www.mydomain.com/shop/bagsSOMETHING_ELSE' onclick="location.href='https://www.mydomain.com/shop/bagsSOMETHING_ELSE' onclick="location.href='https://www.mydomain.com/shop/bagsSOMETHING_ELSE' </code></pre> <p>This assumes, obviously, that your tools supports lookaround.</p> <p>This should certainly work if you just use Perl directly rather than via your magic tool</p> <pre><code>perl -pi -e '/s/(?&lt;=\Qhttps://www.mydomain.com/shop/bags\E)\?cid=[^\']++(?=\')/SOMETHING_ELSE/g' *some_?glob*.pattern </code></pre> <p><strong>EDIT</strong></p> <p>Another idea is to use a capturing group and a backreference, replace</p> <pre><code>(\Qhttps://www.mydomain.com/shop/bags\E)\?cid=[^']++ </code></pre> <p>With</p> <pre><code>$1SOMETHING_ELSE </code></pre> <p>Another test case in Java:</p> <pre><code>public static void main(String[] args) { final String[] in = { "onclick=\"location.href='https://www.mydomain.com/shop/bags?cid=Black'", "onclick=\"location.href='https://www.mydomain.com/shop/bags?cid=Beige'", "onclick=\"location.href='https://www.mydomain.com/shop/bags?cid=Green'" }; final Pattern pattern = Pattern.compile("(\\Qhttps://www.mydomain.com/shop/bags\\E)\\?cid=[^']++"); for(final String string : in) { final Matcher m = pattern.matcher(string); final String replaced = m.replaceAll("$1SOMETHING_ELSE"); System.out.println(replaced); } } </code></pre> <p>Output:</p> <pre><code>onclick="location.href='https://www.mydomain.com/shop/bagsSOMETHING_ELSE' onclick="location.href='https://www.mydomain.com/shop/bagsSOMETHING_ELSE' onclick="location.href='https://www.mydomain.com/shop/bagsSOMETHING_ELSE' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload