Solution 1 :

Assuming all the URLs begin with https_imgur.com, this should find them all and replace them.

let text = `Some stuff here. https_imgur.com/WERTYU.jpg
Some more stuff.
https_imgur.com/DRTYSF.jpg blah blah`;

let result = text.replace(/https_imgur.com/w+.jpg/g, '<img src="$&">');
console.log(result);

$& in the replacement string gets replaced with the match for the regexp.

Solution 2 :

Consider the following example.

jQuery(function($) {
  var postData = $("article").html();
  var regex = /https://i.imgur.com/w+.jpg/g;
  var subst = `<img width='340' src="$&">`;
  $("article").html(postData.replace(regex, subst));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<article>
  <p>Look at this.</p>
  
View post on imgur.com
<p>Look at that.</p>
View post on imgur.com
<div>https://i.imgur.com/qWF0ArM.jpg</div> </article>

You will have to examine the Source of the resulting Post. Then adjust your Selector properly.

Problem :

i need your help i have a list like this of urls

https_imgur.com/WERTYU.jpg
https_imgur.com/DRTYSF.jpg

i need to change them to an html img tag like this

<img src="https_imgur.com/WERTYU.jpg">
<img src="https_imgur.com/DRTYSF.jpg">

i tried to use regex but i can’t find a solution

my idea is adding prefix and suffix to img url

Comments

Comment posted by Barmar

There’s no need for a regexp. Just use string concatenation or a template literal.

Comment posted by Barmar

Or use

Comment posted by cine ebay

because these urls are in wordpress post and i can just use find and replace plugin with regex

Comment posted by Barmar

Well, that’s different. You said you had a list of urls, not a block of text containing urls somewhere in it.

Comment posted by cine ebay

yes maybe i didn’t explained verry well thanks

Comment posted by cine ebay

yes sir it is working in js code snippet

Comment posted by cine ebay

but in the replacement string i don’t know what to do

Comment posted by Barmar

Assign it back to the

Comment posted by regex101.com/r/W8xJuz/1

in this example you will understand what i mean

Comment posted by regex101.com/r/5CYQ7Z/1

Select the JavaScript flavor to get

By