Regex to convert URLs to HTML <a href> hyperlinks in Notepad++? - regex

I have a list of URLs in a text file I am trying to change to HTML, but I'm failing miserably.
My URLs are in this format:
http://mydomain.com/here-are-my-links.html
Does anybody know of a regex search/replace command I can run in Notepad++ to change my URL list to this format:
here are my links

Use the regex
(http://mydomain.com/(.*?)\.html)
and replace it with
\2
If you want to change - into space you can do this
-(?=[^<>]*?</a>)
and replace it with

Related

Regex to delete js HTML attributes

I've got this file from google that has these js attributes like jsname="data", jscontroller="data" etc.
I'd like to use Atom's find and replace with regex feature to replace all attributes beginning with js*="*" with blanks.
How would the regex for this be?
So <div class="l-o-c-qd" jsname="name" jscontroller="somecontroller">Text</div>
will be <div class="l-o-c-qd">Text</div>
Search correct RegEx corresponding to js*="*" en replace it with nothing (check space before/after for avoid double spaces after replacement)

PDF matched incorrectly for image only href/src urls

I am trying to get my regular expression to match any image url with certain optionals.
In my set that matches image file extensions everything is fine until I put in the gif extension. When I do that the pdf urls get matched for some reason.
Could anyone shed light on this?
I am using this within PHP with preg_match_all function
Rules for matching
Can be either src or href link
Can be relative or absolute link
Protocol can be http or https if given
Select only the link if matched
Case insensitive and global
Pattern (Take out gif and pdfs are skipped)
[src|href]="([(https|http):\/\/]?[^"]*.[jpg|png|jpeg|gif])"
Test strings
Should match <a href="http://blog.mysite.com/wp-content/uploads/2014/04/13061-someimage.jpg">
Should match <a href="/wp-content/uploads/2014/04/13061-someimage.jpg">
No match
No match
Should match <img href="http://blog.mysite.com/wp-content/uploads/2014/04/13061-someimage.jpg"/>
Should match <img href="/wp-content/uploads/2014/04/13061-someimage.gif"/>
Should match <img href="http://blog.mysite.com/wp-content/uploads/2014/04/13061-someimage.jpg" />
Should match <img href="/wp-content/uploads/2014/04/13061-someimage.jpg" />
www.regex101.com fiddle: https://regex101.com/r/x3vVSx/1
Thanks to #Micha Wiedenmann for this.
Quote/Unquote
You mixed up [ and (, you want (jpg|png|jpeg|gif) instead of [jpg|png|...]. Similarly for [src|href].

Regex to get part of image url (sublime text 3)

I have a XML database containing several thousand positions. Text + html tags (images and links). I need a regex for Sublime Text 3 to replace a portion of the every image url (everything before file name).
For example, I have this:
<img src="/images/fanart/bigfana2121rt/215627676.jpg">
and
<img src="/images/screenshots/goodlooking/tret/215627676.gif">
And I need to get this:
/images/fanart/bigfana2121rt/
and this:
/images/screenshots/goodlooking/tret/
Thank you.
Regex:
<img\b[^>]*\bsrc="([^"]*\/)[^\/"]*"[^<>]*>
Replacement string:
\1
DEMO

Regex/Notepad++ to strip everything but links from an HTML page?

I have a long page of HTML code. Sprinkled in the code is a variety of links in the form of
Whatever
What regex do I need for Search|Replace in Notepad++ to strip out the entire page of HTML and just leave an isolated listing of the links like this:
whatever.com
whichever.com
whoever.com
Use the following:
Find:
^[^"]+.([^"]+).*
Replace:
$1
To filter the title,
Find:
</?[^>]*.
Replace:
empty string

how to add after img tag using regex cs6

I many files of pages which has images in. I need to add a </center> after each IMG tag. I'm using dreamweaver cs6 and I got this regex so far.
find <img [^>]+> and replace $&</center>
But it doesnt work. It finds and replaces the <img> tags ok but it doesn't add the </center>
Thanks in advance.
I dont know how this are done in dreamweaver, but to keep the "found" value you should add \1 - first regexp, \2 second and so on
\1</center>
or try $1 as in htaccess, but \1 is your best bet
Try this as your regex:
(<img [^>]+>)
and this as your replace string:
$1</center>
You need to add round brackets to create a capturing group which you can then reference with $1.
NOTE: Make sure you have changed the Search field to Source Code, deselected the Ignore whitespace and Match whole word checkboxes and selected the Use regular expression checkbox in the Find and Replace dialog.