Reputation: 127
So, I basically have thousands of lines of a wp_post table in the form of sql update statements. I would like to extract all of the image tags from each line, while keeping them on the same line (1 step harder than just extracting), and while retaining the only other variable within that line, which is always at the end. I can regex image tags out of the file, but that leaves me with just 1 tag per line. How can I pull out multiple (unknown amount, and will vary) image tags from each line, while retaining the correct line number?
Example:
Insert into `table` (post_content, guid) values ('<img src="blah">alkajsdljasdmorecontent<img src="blaaaa">','http://foo.com');
Insert into `table` (post_content, guid) values ('<img src="blah">alkajsdljasdmorecontent','http://foo.com');
Insert into `table` (post_content, guid) values ('<img src="blah">alkajsdljasdmorecontent<img src="blaaaa"><img src="blaaaa">','http://foo.com');
I would like to return:
<img src="blah"><img src="blaaaa"> http://foo.com
<img src="blah"> http://foo.com
<img src="blah"><img src="blaaaa"><img src="blaaaa"> http://foo.com
I could normally run something like
<img.*?>
to extract all image tags, but I want the image tags to stay on the line they came from, and retain the ending value (the guid) on each line as well.
I could use something like
.*(<img.*?>).*'.'(http://.*?)'\);\r
to return what i want for the second example, but it would not return both or all three image tags in the first or third example...
Any ideas? Or do you understand what I mean?
Upvotes: 2
Views: 75
Reputation: 10525
You can use this.
Find: (<img.*?>)|(http:.+\b)|(.)
Replace \1\2
Click on Replace All
Upvotes: 1