I was following this article about find and replace but have not been able to get it working for what I need to do...
What I need to find and replace it all links that contain ../external.html?link=something.html and replace them with #
This is what I tried to do in dreamweaver search
FIND:
<a href="../external.html?link=[^<]*"
REPLACE WITH
<a href="#"
But the problem is using that search does not find anything.
I figured it out from adobe documentation on the subject: http://help.adobe.com/en_US/dreamweaver/cs/using/WScbb6b82af5544594822510a94ae8d65-7c3ea.html#WScbb6b82af5544594822510a94ae8d65-7c1fa
The problem was that because the string i was search for had ? in it and the wildcard search is a regular expression. So to fix it I had to put a back slash before the ? character e.g: \?
This escapes the character and I was able to complete my task.
Hopefuly someone else who gets confused on this subject will find this helpful!
Related
I'm currently cleaning up an XML file manually and removing unnecessary content and tags. It would help hugely if I could find all instances of a tag with its dynamic content and remove it with SublimeText Regex. How do I do this?
This is the tag that needs to be found. The content within the quotes is dynamic, which means I can't do simple find replace:
[simple_tooltip content='Colour Printer']
Is there a regex syntax that can help me kill the content within the quotes?
I've Googled a bit and haven't been able to find a clear way of doing this. However, regex is also confusing... Any help is greatly appreciated. Thanks
I don't use Sublime so this may be a little off, but I think you're looking for something like this?
Find content='.+?' Replace content=''
Explanation
Match content=' literally
Match . (any character) + (1 or more times) ? (lazily)
Match ' literally
I have a WordPress plugin where I recently used regex to search and replace, however, I am finding it tricky to remove a space that now remains.
I have a YouTube link, which I managed to use regex to add:
[embed](youtubelinkhere)[/embed]
However, there is a space that I can't get rid of before [/embed] that is causing some issues.
What should I search for to remove this space before [/embed] please?
Many thanks.
You'll have to escape the square brackets:
\s\[\/embed\]
Live Demo
https://regex101.com/r/fT4dP3/1
I created a regex string that I hoped would get both the link and the associated text in an html page. For instance, if I had a link such as:
<a href='www.la.com/magic.htm'>magicians of los angeles</a>
Then the link I want is 'www.la.com/magic.htm' and the text I want is 'magicians of los angeles'.
I used the following regex expression:
strsearch = "\<a\s+(.*?)\>(.*?)\</a\s*?\>|"
But my vb program told me I was getting too many matches.
Is there something wrong with the regEx expression?
The circle-brackets are meant to get 'groups' that can be back-referenced.
Thanks
What about this one:
\<a href=.+\</a>
All there is left to do is to go over each match and extract the substrings using regular string manipulation.
Check here (although regexr follows javascript regex implementation, it is still useful in our scenario)
With that being said, I often see people stating that regexes are not suited for parsing Html. You might need to use an Html Parser for this. You have HtmlAgilityPack, which is not maintained anymore, and AngleSharp, that I know of to recommend.
I tried with following pattern , it worked.
\<a href=(.*?)\>(.*?)\<\/a\s*?\>|
Also Found two errors on your origin string:
missed a escape syntax on /a
the reserved word 'href' is captured on
first group
At last , i would like recommend you a great site to test REGEX string. It will helps your debug really fast. Refer this (also demonstrating the result you want) :
REGEX101
Hi guys I really need some help, I need to do a mass replace expression in files
I have a large list of urls which needs to be replaced.
I want to search files and replace each with the appropriate brand anchor link e.g.
http://www.example.com
becomes
<a href=”http://www.example.com”> http://www.example.com</a>
I need to do this with a large list of urls in multiple files
I tried the following expression
(1)|(2)|(3)
(?1a)(?2b)(?3c)
But It doesn’t work. This is beyond me. Any help would be appreciated. Thanks
Go to Search > Replace menu (shortcut CTRL+H) and do the following:
Find what:
http:\/\/www\.\w+\.com
Replace:
$0
Select radio button "Regular Expression"
Then press Replace All in All Opened Documents
You can test it and see the results at regex101.
Important note: matching URLs with regular expressions can be complicated! I gave you the simplest example matching only URLs like http://www.example.com. If you have more complicated stuff, let us know but showing some of your data! More info on this matter here and here.
UPDATE:
Let's make it slightly more complicated to match also
yoursite.com/index.php?remainingurl
Find what:
(?:https?:\/\/)?(?:www\.)?(\w+\.\w{2,6})(?:\/\w+\.\w+(?:\?\w+)?)?\b
Replace:
$1
I have to deal with a problem and maybe you can help.
I took over a Website with a lot of code and would like to have it run on PHP 5.4.
But there are a LOT of statement's like this:
if($arrayname['keyname']>"") ....
I would like to replace them all with:
if(!empty($arrayname['keyname'])) ....
Doing it manually will take forever :-(
Do you know how to use Dreamweaver's CS5 search & replace with RegEx capabilites - unfortunately my RegEx knwoledge is limited.
Of course the regex must be "variable, as the arrayname and the keyname always changes.
Any help on finding the correct RegEx Stamtent is HIGHLY appreciated .
Regex to find all occurrences of if($arrayname['keyname']>""), whatever arrayname and keyname are, if only letters :
if\\(\\$[a-zA-Z]*\\[\'[a-zA-Z]*\'\\]>\"\"\\)
You'll have to find how to use BackReferences in Dreamweaver. If it uses standard Regex, then use the tutorial in the link, it will be of great help for you.
To complete and close this question:
In Dreamweaver search for (Regex Search in Code):
if\(\$(\w+)\[['"](\w+)['"]\]>""\)
Replace by:
if(!empty($$1['$2']))