Note that there are some explanatory texts on larger screens.

plurals
  1. POMatch a string in a string containing certain string in Javascript
    primarykey
    data
    text
    <p>Sorry for the awful title - not sure how best to put it.</p> <p>note: Am trying to do this in Javascript</p> <p>I want to match specific text within 2 different urls which are of differing length and structure. One starts with <code>video</code> and the other with say <code>audio</code>. The match must be replaced differently depending on the start of the string.</p> <p>I can't work out how to make a dotall (.*) match in a positive lookbehind?</p> <p>For example, the strings below ought to be matched by 2 separate RegEx's, one specifying that <code>video</code> and the other <code>audio</code> must be before <code>%7bmatch%7d</code> They must <strong>only</strong> match <code>%7bmatch%7d</code> for the given string beginning.</p> <pre><code>video://lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@length/%7bmatch%7d/lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@length audio://lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@length/%7bmatch%7d/lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@length </code></pre> <p>I have tried: <code>/(?&lt;=video)(?&lt;=.*)%7bmatch%7d/g</code> <a href="http://regexr.com?373gh" rel="nofollow">http://regexr.com?373gh</a> amongst other variants and can't quite seem to only match the <code>%7bmatch%7d</code> or any other match without getting everything since <code>video</code> in the example. Got me stumped, would really appreciate a nudge in the right direction.</p> <p><strong>EDIT:</strong> Answer specific to Javascript:</p> <pre><code>// Random collection of string(s) var inputString = "video://lots0fr@ndomcharacasdf/asd/ft#Rsinbetweenof1nd1scrimin@length/%7bmatch%7d/lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@lengthaudio://lots0fr@ndomcharact#Rsinbet/asdfas/dweenof1nd1scrimin@length/%7bmatch%7d/lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@lengthvideo://lots0fr@ndomcharact#Rsinbetweasdf/asd/f/asdfenof1nd1scrimin@length/%7bmatch%7d/lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@lengthaudio://lots0fr@ndomcharaasdfafsdct#Rsinbetweenof1nd1scrimin@length/%7bmatch%7d/lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@lengthvideo://lots0fr@ndomcharact#Rsinfasdfasdfbetweenof1nd1scrimin@length/%7bmatch%7d/lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@lengthaudio://lots0fr@ndomcharaasdfasdf///asdfasdfct#Rsinbetweenof1nd1scrimin@length/%7bmatch%7d/lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@length"; // Regex to match after every `video` occurence regexVideo = new RegExp(/(video.*?)%7bmatch%7d/g); // Regex to match after every `audio` occurence regexAudio = new RegExp(/(audio.*?)%7bmatch%7d/g); // strings to replace the matches var replaceStringVideo = "&lt;span class='woot'&gt;W00tW00tVideoW00t&lt;/span&gt;"; var replaceStringAudio = "&lt;span class='woot'&gt;W00tW00tVAudioW00t&lt;/span&gt;"; // replace both audio and video with respective replace values NOTE: the dollar token needed concatenated before the replaceString. inputString.replace(regexVideo, "$1" + replaceStringVideo).replace(regexAudio, "$1" + replaceStringAudio); // This yields an inputString value of "video://lots0fr@ndomcharacasdf/asd/ft#Rsinbetweenof1nd1scrimin@length/&lt;span class='woot'&gt;W00tW00tVideoW00t&lt;/span&gt;/lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@lengthaudio://lots0fr@ndomcharact#Rsinbet/asdfas/dweenof1nd1scrimin@length/&lt;span class='woot'&gt;W00tW00tVAudioW00t&lt;/span&gt;/lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@lengthvideo://lots0fr@ndomcharact#Rsinbetweasdf/asd/f/asdfenof1nd1scrimin@length/&lt;span class='woot'&gt;W00tW00tVideoW00t&lt;/span&gt;/lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@lengthaudio://lots0fr@ndomcharaasdfafsdct#Rsinbetweenof1nd1scrimin@length/&lt;span class='woot'&gt;W00tW00tVAudioW00t&lt;/span&gt;/lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@lengthvideo://lots0fr@ndomcharact#Rsinfasdfasdfbetweenof1nd1scrimin@length/&lt;span class='woot'&gt;W00tW00tVideoW00t&lt;/span&gt;/lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@lengthaudio://lots0fr@ndomcharaasdfasdf///asdfasdfct#Rsinbetweenof1nd1scrimin@length/&lt;span class='woot'&gt;W00tW00tVAudioW00t&lt;/span&gt;/lots0fr@ndomcharact#Rsinbetweenof1nd1scrimin@length" </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.
 

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