Notepad ++ Find all lines containing xxxxxx/Reports/reportname.pdf and replace with xxxxxx/Reports/PDF/reportname.pdf - regex

Screenshot of the fileI have a file which contains multiple lines
Source Path Target Path
xxxx/out/reportname1.pdf xxxx/out/Reports/reportname1.pdf
xxxx/out/reportname2.txt xxxx/out/Reports/reportname2.txt
xxxx/out/reportname3.csv xxxx/out/Reports/reportname2.csv
I would like to replace /Reports/reportname1.pdf to /PDFReports/reportname1.pdf for only PDF files.
Please suggest I tried using /Reports/.*pdf and I am able to find it, but unable to replace it

Search for \/Reports\/(.*?\.pdf) and replace with /PDFReports/$1

You would need to use replacing with regex syntax (ctrl+H by default)
Try something like:
Find what:
\/Reports\/(.*\.pdf)
Replace with:
/PDFReports/$1
And use "regular expression" search mode.
This mechanism is called capture group - braces in "Find what" are used to remember the content inside them and then this content is references later by $1.
Note - you might have to use "\1" instead of "$1" in case of old version of Np++

searching pattern: ([\w\_]+\.\w+)
replace to: Reports/$1
output:
xxxx/out/Reports/reportname1.pdf
xxxx/out/Reports/reportname2.txt
xxxx/out/Reports/reportname3.csv
EDIT: since filenames could containt _, little upgrade.

Related

VS 2017 find and replace ConfigurationManager.Appsettings["stringname"]

I am trying to find and replace ConfigurationManager.Appsettings["stringname"] and Convert.ToInt32(ConfigurationManager.Appsettings["stringname"]) (where "stringname" could be any valid AppSetting name) in all the files in my project with a call to a custom method which wraps this.
There are around 1000 of these entries in the project, trying to avoid doing this manually on each file.
Is there a better way to do this? Gave a few tries with the Find in all files with a regex, but with no luck.
Thanks in advance.
You should be able to match and replace all with this regex:
ConfigurationManager.Appsettings\[([^\])\]
The regex search for the string 'ConfigurationManager.Appsettings[', then creates a capturing Group containing the content of the Square brackets.
You then need to replace with:
ClassA.Method($1)
That will replace with the string, where '$1' will be replaced by the matched Group 1 from the regex (which would be for instance '"SessionTimeout"').

VS Code, find/replace access find results in the replace field

I have phone numbers on my file and I would like to surround each of them with braces, so if I have this:
"+49-1111"
"+49-2222"
I would like to run a replace operation and to get this:
["+49-1111"]
["+49-2222"]
Is that possible with the current vs code find/replace action?
If it is a dup sorry but I could find any explanation anywhere.
Thanks
This is more relevant to regular expression.
Find ("\+\d{2}-\d{4}"), replace the occurrences with [$1]
Be sure to turn the "Use Regular Expression" switch on.

Find and replace with regular expressions in Intellij

I got the following string:
http://www.foo.com/images/bar/something/image.gif|png
I would like to replace all the occurences of such string as:
<someTag>/images/bar/something/image.gif|png</someTag>
How can I achieve this using a regEx?
To open Replace in Path popup press Ctrl+Shift+R (or on mac Cmd+Shift+R).
If you want to switch everywhere in your project, make sure the scope is In Project.
Make sure Regex? is checked and put the next values in the boxes:
(http://)([a-zA-Z.0-9]*)([a-zA-Z.-/0-9#?%&|]*)
<someTag>$3</someTag>
You will need to make sure all the characters you need are in the expression. For example strings with # will not be replaced as expected.
The way this works is the patterns matched are matched in 3 groups and by using the parenthesis and then only the 3d group is being used to replace the string found.
Example:
Good luck!

Regular Expression to Remove Subdomains from Domain List

I have a list of domains and subdomains stored in a .txt file (I'm using Windows XP).
The format of the domains is this:
somesite1.com
sub1.somesite1.com
sub2.somesite1.com
somesite2.com
sub1.somesite2.com
sub2.somesite2.com
somesite3.com
sub1.somesite3.com
sub2.somesite3.com
I use notepad++, and I need to use regular expressions
Anyway, I don't know what to put in the find & replace boxes so it can go through the contents of the file and leave me with only the root domains. If done properly, it would turn the above example list into this:
somesite1.com
somesite2.com
somesite3.com
Can somebody help me out?
Thank you in advance.
It's an old question, but the answers provided didn't work for me. You need a negative lookahead. The correct regex is:
^\w*\.(?!\w+\s*\n)
You can use:
Find what: [^\r\n]+\.[^.\r\n]+\.[^.\r\n]+[\r\n]+
Replace with: empty_string
with regular expression checked and dot match line-feed NOT checked
I suggest using the Mark tab of the Notepad++ Find dialogue. Enter the regular expression ^\w+\.\w+\.\w+$, make sure that Bookmark line is selected, then click Mark all. Next, use Menu => Search => Bookmark => Remove bookmarked lines. These will remove all entries having with three "words" separated by two dots. It will leave all other lines in place.
An alternative is to mark all lines matching the regular expression ^\w+\.\w+$ and use the Remove unmarked lines menu entry. This I do not recommend as it will remove all lines with an unexpected format as well as the lines for subdomains.
Another method would use the Replace tab of the Notepad++ Find dialogue. Enter the regular expression ^\w+\.\w+\.\w+\r\n in the Find what field, and leave the Replace with field empty. The \r\n part of this expression may need some adjustment to account for the line endings set on the file.

How do I do a regex search and replace in sublime text 2?

I want to remove inline style from an html document in ST2.
I imagine my regex will be something like this
style=\"*\"
If that's wrong, it doesn't matter. I'm sure I'll figure out the expression I'll need.
What I haven't been able to figure out, is how to actually use a regex to find or to find and replace text in ST2. The docs say that it can be done. But I can't find the documentation for how to do it.
Simply open the Search+Replace function (via Ctrl-H or the menu bar) and check the first box on the left of it (the one with an '*' on it, or you can press Alt+R)
Then the search field will be used as a Regex, and you can use the found patterns using the usual $1, $2, $3 vars in the replace box
More info here
I had a similar task to perform, the regex I used in the manner that Nas62 suggested was
style=\"(.*?)\"
Find What : style=".*" Replace With : leave it as blank
Click Replace All button.