Change all href links in Dreamweaver using RegEx - regex

I am trying to use Dreamweaver Find and Replace regex feature, to find and replace all href links that start with "/url-to-page.html" to "./url-to-page.html"? But not sure how to do so. Can someone please help with any example on how to do so (Regex required to do so) ? Thanks

Find : <a href="\/(.*?)">
Replace: <a href="./$1">
Make sure you check Use regular expression at the bottom

I would say if you just had to do this for a single string:
Find: .*/url-to-page.html
Replace: ./url-to-page.html

href="(.*)" to search and find it in all your tags
attributeName=(.*) to pin your regex search

Related

How to extract the name out of this html with regex

<a rel="profile-edit" class="app js-user-name" href="/profile/0471482493?from_my_profile=1">Mia</a></b> <
Hello I have a variable defined with the above text can someone please tell me the regex that would be required to extract jst the word "Mia" from the html? The word will not always be Mia.
Thank you in advance
Use this pattern:
/>.*?([^<]+)/
Online Demo

Sublime: replace everything between quotes

I need some help with Regular expression to Search and Replace in Sublime to do the following.
I have HTML-code with links like
href="http://www.example.com/test=123"
href="http://www.example.com/test=6546"
href="http://www.example.com/test=3214"
I want to replace them with empty links:
href=""
href=""
href=""
Please help me to create a Reg. ex. filter to match my case. I guess it would sound like "starts with Quote, following with http:// .... ends with Quote and has digitals and '=' sign", but I'm not very confident of how to write this in Reg. ex. way.
(?<=href=")[^"]*
Try this.Replace by empty string.
See demo.
https://regex101.com/r/sH8aR8/40

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.

VIM Relace all <a ...> and </a>?

Sorry this might be a simple question, but I could not figure it out. What I need is to filter out all the <a href...> and </a> strings out from a html text. Not sure what regular expression I should use? I tried the following search without any luck:
/<\shref^(>)>
what I mean here is to search for any string starting with "< href" and any string not containing '>' and finally '>'. My search code is not working. What is the correct one?
If I understand what you're looking for it should be <\shref[^>]*>.
Another way would be to use non-greedy matching:
/<a\shref.\{-}>
I think I got it:
/<a\shref[^>]+>
where [] is a set and ^ is not.

How to Find Quotes within a Tag?

I have a string like this:
This <span class="highlight">is</span> a very "nice" day!
What should my RegEx-pattern in VB look like, to find the quotes within the tag? I want to replace it with something...
This <span class=^highlight^>is</span> a very "nice" day!
Something like <(")[^>]+> doesn't work :(
Thanks
It depends on your regex flavor, but this works for most of them:
"(?=[^<]*>)
EDIT: For anyone curious how this works. This translates into English as "Find a quote that is followed by a > before the next <".
Regexes are fundamentally bad at parsing HTML (see Can you provide some examples of why it is hard to parse XML and HTML with a regex? for why). What you need is an HTML parser. See Can you provide an example of parsing HTML with your favorite parser? for examples using a variety of parsers.
If you are using VB.net you should be able to use HTMLAgilityPack.
Try this: <span class="([^"]+?)?">
This should get your the first attribute value in a tag:
<[^">]+"(?<value>[^"]*)"[^>]*>
If your intention is to replace ALL quotation marks within tags, you could use the following regular expression:
(<[^>"]*)(")([^>]*>)
That will isolate the substrings before and after your quotation mark. Note that this does not attempt to match opening and closing quotation marks. It simply matches a quotation mark within a tag.