How to wrap links in <a> with Notepad++ Find/Replace function? - html

I have a text document with raw links (not wrapped) and I would like to wrap them in HTML anchor tags.
Link example:
http://example.com/images/my-image.jpg
Desired output:
http://example.com/images/my-image.jpg
I can FIND the links in Notepad++ using the following RegEx:
[-a-zA-Z0-9#:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9#:%_\+.~#?&//=]*)?(\?([-a-zA-Z0-9#:%_\+.~#?&//=]+)|)
However, the REPLACE string I'm trying is not working for some reason:
\1
How can I do this with notepad++?

You need to replace with the backreference to the whole match:
$&
Or
$0
Here, the $0 and $& "insert" the text that is matched by the whole regular expression, not just by some capturing groups.

Related

regex interprete markdown but ignore HTML

In a string like
Hallo, this is <code>`code`</code> and this `is code again`.
To analyse it, parse it with regex?
In this example the user just typed the far right ` at the very last. The first "code" has obviously already been surrounded by HTML.
I need a regex to get the next code indicated part.
There always be one series, that is valid markdown AND not already surrounded by the corresponding HTML tags.
How to get this specific series (regardless if it's *, **, ___, ` or whatever)?
So what you want is a regex that only matches the markdown that isn't surrounded by HTML tags right ?
You can use something like this :
/(?:[^<>]|^)(`[^<>].*?`)/
This will only match the text placed inside `` that aren't directly placed next to a < or > character. This way, no matter what the HTML tag is inside the <...>, the `code` won't match.
See this Regex101.com
If you want to match every emphasized string that is not tagged with "code" you can use
(?<!<code>)`[\w ]+`
You can test it on regex101.com

Search and replace outer tag in Atom using REGEX

Using Atom, I'm trying to replace the outer tag structure for multiple different texts within a document. Also using REGEX, which I'm not versed enough to come up with my own solution
HTML to be searched <span class="klass">Any text string</span>
Replace it with <code>Any text string</code>
My REGEX (<?span class="klass">)+[\w]+(<?/span>)
Is there a wildcard to "keep" the [\w] part into the replaced result?
You can use a capture group to capture the text in between the <span> tags during the match, and then use it to build the <code> output you want. Try the following find and replace:
Find:
<span class="klass">(.*?)</span>
Replace:
<code>$1</code>
Here $1 represents the quantity (.*?) which we captured in the search. One other point, we use .*? when capturing between tags as opposed to just .*. The former .*? is a "lazy" or tempered dot. This tells the engine to stop matching upon hitting the first closing </span> tag. Without this, the match would be greedy and would consume as much as possible, ending only with the final </span> tag in your text.

How do I replace <code> HTML tags with backticks in Atom?

I have been trying to switch between a WordPress blog and a Jekyll blog. As part of this I would like to convert <code> tags (and its closing tag </code>) with backticks (`). My text editor is Atom and I would like to be able to automate this action using Atom's RegEx search function.
Search:
</?code>
Replace with:
`
The regex </?code> matches either <code> or </code>, because the ? quantifier makes the preceding token optional (the /).

Regex that matches any HTML tag with the content inside

I'd like to use Regex to match HTML tag "head" and text inside them so I can delete them easily. I'm using a find and replace tool that is utilizing regex syntax and it really works great in replacing multiple files at once.
I tried doing a lot of syntax but I always fail.
http://regex101.com/r/aZ6pN5/2
Anyone can help please?
Replace .* in your regex with [\S\s]*?, so that it would match line breaks also. You can't use s DOTALL modifier in JavaScript.
<head.*?>([\s\S]*?)<\/head>
[\s\S]*? This would do an non-greedy match of zero or more space or non-space characters.
DEMO
OR
To replace the contents of head tag.
(<head\b[^<>]*>)[\s\S]*?(<\/head>)
Replacement string:
$1stringyouwant$2
DEMO

What is the appropriate regex string to match a specific html element?

I have a ton of text replacements to make and I would like to try and do this all at once instead of manually. I'm trying to replace <a class='stuff morestuff' href='#'>Some Text</a> with Some Text; essentially stripping off the surrounding anchor tag.
I've been messing around with a search/replace in Visual Studio using regex, but am not really getting anywhere. My latest attempt:
Find what:
\<a class='stuff morestuff' href='#'\>(.+)\<\/a\>
Replace with:
$1
If what I want to do is even feasible, how can I correct my regex to accomplish this?
This regex will match your anchors if the class and href are always the same:
Find: \<a[^\>]class='stuff morestuff' href='\#'[^\>]*\>(.*)\</a\>
Replace: $1
This regex will replace all the anchors with the inner text:
Find: \<a[^\>]*\>(.*)\</a\>
Replace: $1
I'm assuming from your post you plan to use this in Visual Studio's Find/Replace and not in code.
Find:\\<a class='.*?' href='#'>(.*?)\\</a\\>
Replace: $1