Use Dreamweaver regex to add file extension - regex

I have a project where I've exported an html file to be sanitized in preparation for a language translation. The problem is that the internal links do not have the ".html" extension. I've solved the problem of erasing the long file paths, but appending the remaining file is the problem.
The raw file path is:
href="https://oldsite.com/folder1/folder2/folder3/actualpage
I use this regex to find all instances of 'https://oldsite.com" and subfolders, adapting it to how many subfolders I have:
(https://oldsite.com)+/[a-zA-Z0-9]+/[a-zA-Z0-9]\w+/[a-zA-Z0-9]\w+/[a-zA-Z0-9]\w+/[a-zA-Z0-9]\w+
Leaving me with "href="actualpage"
The ideal result should be:
href="actualpage.html"
I've been researching this for hours and can't figure out how to append ".html" to the page.
I'm even open to an application or script that can automate this process.
Thanks in advance.

After some research and some tutorials, I found a regex that did the trick. After shortening the file paths to one level, I used the following:
In Dreamweaver:
Find:
href="(.*)" title=
Replace:
href="$1.html" title=
I performed a massive Find/Replace and was able to fix 1500 files in minutes. Regex is my jam!
I hope this helps other regex noobs like myself.

Related

Visual Studio Code - Removing Lines Containing criteria

This probably isn't a VS Code-specific question but it's my tool of choice.
I have a log file with a lot of lines containing the following:
Company.Environment.Security.RightsBased.Policies.RightsUserAuthorizationPolicy
Those are debug-level log records that clutter the file I'm trying to process. I'm looking to remove the lines with that content.
I've looked into Regex but, unlike removing a blank line where you have the whole content in the search criteria (making find/replace easy), here I need to match from line break to line break on some criteria between the two, I think...
What are your thoughts on how criteria like that would work?
If the criteria is a particular string and you don't want to have to remember regexes, there is a few handy keyboard shortcuts that can help you out. I'm going to assume you're on a Mac.
Cmd-F to open find.
Paste your string.
Opt-Enter to select all of the instances of the string on the page.
Cmd-L to broaden the selection to the entire line of each instance on the page.
Delete/Backspace to remove those lines.
I think you should be able to just search for ^.*CONTENT.*$\n, where the content is the text you showed us. That is, search on the following pattern:
^.*Company\.Environment\.Security\.RightsBased\.Policies\.RightsUserAuthorizationPolicy.*$\n
And then just replace with empty string.
I have already up-voted answer of #james. But.. still I found one more easy and many feature available extension in VS Code. Here it is
It have much easy options to apply filters.
To match specific case mentioned in question. I am attaching screenshot which display how to use for it. I am posting this for others who come here in search for same issue. (Like I came)

RegEx: Best way to search and replace $!esc.html($!{XYZ})

I have inherited a project that includes html email templates and the text files that get sent along with it.
The back-end puts it all together, so that it's a multipart email message in the end. In other words, if someone has HTML turned off, they can read the text version. TMI.
Problem:
The guy before me left all kinds of $!esc.html($!{XYZ}) in the text files. Where XYZ stands for various different strings in the code.
I haven't touched RegEx in years and am at a loss.
Question
Is it possible to look for every occurrence of such variables in the text files and replace it with: $!{LAST_NAME}?
Can someone point me in the right direction? I have tried one of those RegEx recipe sites, but I got stuck. Any suggestions and/or help with this would be tremendously appreciated.
I am using SublimeText3, and I know how to find & replace in .txt files only.
Peace. Calm. Light.
Not sure what 'flavor' of regex sublime uses, but this should work. I'm assuming the XYZ means it will only be letters in there?
\$!esc\.html\(\$!\{\w*\}\)
The following version accounts for any _'s
\$!esc\.html\(\$!\{(\w|_)*\}\)

grep complete resource url within a file

I have to search and extract within a file addresses like these:
http://deimos.apple.com/WebObjects/Core.woa/DownloadRedirectedTrackPreview/unina.it-dz.5373092572.05373092574.12739786322/enclosure.m4v
They are 38 links with only the last serie of digit which change.
I tried with this regexp:
grep -io 'http://ex[a-z.-]*/[a-z0-9+-]*/[a-z0-9.,-+]*[.m4v]'
it extract all the urls present in the file which point to an m4v file but not the complete url it get a partial url as follow:
http://deimos.apple.com/WebObjects/Core.woa/DownloadRedirectedTrackPreview/unina.
Where am I wrong?
I can't figure out why it happens.
Thanks a lot for your effort.
Your regex and your extracted filename do not match. The filename that you list does not begin with:
http://ex
Which your regex requires. you could change your regex to something more like this which would match your URL:
'http://(?:[a-z0-9+-]+/)*[a-z0-9+-]+\.m4v'
Sorry Jonathan it was a typing mistake while I posted in my regex was correctly used dei and not ex as written.
But the problem persisted.
Marc opened my mind.
I knew how the address starts so I tried with
grep -io 'http://dei/.m4v'
no success :-(
fedorqui gave the last hint, maybe the problem was a dot
so I tried
grep -io 'http://deimos./.m4v' :-D
and it did the trick!
Now I have the file to give to wget to automate multiple file downloads without proprietary softwares needing.
The files are podcasts of juridic lessons released free as in freedom but only in an easy way for who would buy Apple or Microsoft (iTunes).
Now I have the file to give to wget to automate multiples file downloads without soiling my system with emulators and proprietary software.
Thanks to all indeed!!

IntelliJ / PyCharm navigate by Regex

I'm a pretty avid user of PyCharm but still having to use Sublime for some things most days and there is always some niggly little things that i find annoying in both. Another one i've just stumbled across not having the ability to regex search navigate File, Class, Symbol etc.
In Sublime i can do cocbas and it will give me templates/cocreate/base.html but in PyCharm it will just give me nothing found as Sublime matches it to the path.
Is there anyway to get regex searching on paths for File navigation?
first of all your cocbas search is not "regex" search.
In intellij, you can search file by pressing ctrl-shift-n, then you can for example:
for file fooo/bar/blah/IAmHere.html do f/b/b/iam you will see the file in the list, in fact you can just typeiah the file would be shown in list too.

Append Filename of Txt Files on a Line Inside the File Notepad++

I 'm not a coder/programmer so my knowledge about regex is limited on what I can find on Google and sites like stackoverflow.
I have a series of files, around 10k with different filenames. Now I want to put the specific filename of each file into a line within the txt file, preferably on the first or last line of the file.
So if I have a file with the filename Caste "System in Nepal.txt" I want to see "Caste System in Nepal" on either the first or second line of the txt, without the quotes.
Can anybody help me? Thanks a lot. :)
Have a go with the following:
(.+?)\.\w+
The bit in the brackets you'd then use for your file name. This assumes that there is only one dot in the filename before the extension. Otherwise, if you have filenames like Document.name.txt, you'll need a more complex regex.
I'm not sure you can do this from within Notepad++ as you'll need the list of files to begin with. If you already have this then you can use find and replace to find .txt (if they all have the .txt extension) and replace it with nothing. If you have other extensions then try a regexp like \.[^\.]$ and replace it with nothing. That should match the last fullstop and everything after it.
If you don't have the list of files in your text editor then you can get them from a Bourne compatible shell with something like find . -type f -print > ../file-you-want-the-list-in.txt run in the directory with all the files in.