Regex in dreamweaver and notepad++ - regex

I have a problem. I need to use regex in notepad++ or dreamweaver or someother editor to handle a large number of .html files.
I need to find all html files that contains line below - but - there is a important thing.
/myfolder/401(something)a.js
It must find files that contains line above but ONLY those files that have at least one digit between
/myfolder/401(at least one digit 0-9)c.js!!!
It can contain letters but it must have in one place between 201------a.js at least one or more digits.
If there is no digits between 401--a.js than skip it(dont mark that one).
For example:
/myfolder/401dhfgsadfdf1a.js
/myfolder/401d7sd7fdf8a.js
Those above mark as correct but:
/myfolder/401dfdsfsdfsa.js
The above don't mark because it doesn't contain not a single digit between 401 and a.js
Is there any regex expert around here? Thank's in advance for any help.

Inside notepad++ i ran this query in the find dialog
/myfolder/401.*\d.*a\.js
Locate something that starts with /myfolder/401 > has anything with at least a digit > a.js
With the following as my test data
/myfolder/401dhfgsadfdf1a.js
/myfolder/401d7sd7fdf8a.js
/myfolder/401dfdsfsdfsa.js
and the result of "File all in Current Document" were:
Search "/myfolder/401.*\d.*a\.js" (2 hits in 1 file)
new 2 (2 hits)
Line 1: /myfolder/401dhfgsadfdf1a.js
Line 2: /myfolder/401d7sd7fdf8a.js

Related

How can I define RegEx to remove a particular part in a specified line of code?

I am attempting to remove .nc1 at the end of a line. I receive .nc1 in batches as a steel fabricator. We run into issues with our files where, line 5 in the example below, has an unnecessary .nc1 extension at the end. Problem I have, is that I cannot simply replace the value as it appears in line 2 as well.
In the example photo I have attached, I am looking to remove line 5 .nc1 extension and keep line 2 as is, .nc1 extension removal will be applied in a batch editing to all of my .nc1 files via find/replace.
ST
** BB233.nc1
F88
BB233
BB233.nc1
1000
A992
1
W21X201
Change to this
ST
** BB233.nc1
F88
BB233
BB233
1000
A992
1
W21X201
I was looking into Positive and/or Negative lookahead/lookbehind but didnt have much luck in making it work. I am a novice/lack thereof when it comes to using RegEx.
Match .nc1 only at the end of lines starting with whitespace, capturing the part you want to keep and putting it back, effectively deleting .nc1
Search: ^(\s+.*)\.nc1$
Replace: $1

Search for multiple strings in several files with Sublime 3 using AND

This previous (similar) question of mine Search for multiple strings in several files with Sublime 3 was answered with a way to search for multiple strings in multiple files in SublimeText, using the regex OR operator:
Find: (string1|string2)
Where: <open folders>
This works perfectly for searching files where either string1 OR string2 is present. What I need now is to search in lots of files for both strings present. I.e., I need to use the AND operator.
I looked around this question Regular Expressions: Is there an AND operator? and also this one Regex AND operator and came up with the following recipes:
(?=string1)(?=string2)
(?=.*string1)(?=.*string2)
(string1 string2)
(string1\&string2)
but none of them work.
So the question is: how can I search multiple strings in several files at once with SublimeText?
(I'm using SublimeText 3103)
Add: the strings are not necessarily in the same line. They can be located anywhere within each file. For example, this file:
string1 dfgdfg d dfgdf
sadasd
asdasd
dfgdfg string2 dfgdfg
should trigger a match.
Open sublime Text and press
Shift+Ctrl+F
or click on the Find in Files options under Files tab. The above is keyboard shortcut for this option. When you press above key, these are following options
When you select ... button from above, you get 6 options which are Add Folder or Add Open Files or Add Open Folders
To search strings that occur in the same line
Use the following regex for your and operation
(?=.*string1)(?=.*string2)
I am using the following regex
(?=.*def)(?=.*s)\w+ <-- \w+ will help in understanding which line is matched(will see later)
and I am searching within current open files
Make sure the Use Buffer option is enabled (one just before Find). It will display the matches in a new file. Also make sure the Show Context (one just before Use Buffer) option is enabled. This will display the exact line that matches. Now Click on Find on the right side.
Here is the output I am getting
See the difference in background color of line 1315 and 1316(appearing in left side). 1316 is matched line in designation file
This is the image of last part
There were total 6 files that were opened while I used this regex
For finding strings anywhere in file
Use
(?=[\s\S]*string1)(?=[\s\S]*string2)[\s\S]+
but it will kill sublime if number of lines increases.
If there are only two words that you need to find, the following will work super fast in comparison to above
(\bstring1\b[\S\s]*\bstring2\b)|(\bstring2\b[\S\s]*\bstring1\b)

Notepad++ - Selecting or Highlighting multiple sections of repeated text IN 1 LINE

I have a text file in Notepad++ that contains about 66,000 words all in 1 line, and it is a set of 200 "lines" of output that are all unique and placed in 1 line in the basic JSON form {output:[{output1},{output2},...}]}.
There is a set of characters matching the RegEx expression "id":.........,"kind":"track" that occurs about 285 times in total, and I am trying to either single them out, or copy all of them at once.
Basically, without some super complicated RegEx terms, I am stuck because I can't figure out how to highlight all of them at once, and also the Remove Unbookmarked Lines feature does not apply because this is all in one line. I have only managed to be able to Mark every single occurrence.
So does this require a large number of steps to get the file into multiple lines and work from there, or is there something else I am missing?
Edit: I have come up with a set of Macro schemes that make the process of doing this manually work much faster. It's another alternative but still takes a few steps and quite some time.
Edit 2: I intended there to be an answer for actually just highlighting the different sections all at once, but I guess that it not possible. The answer here turns out to be more useful in my case, allowing me to have a list of IDs without everything else.
You seem to already have a regex which matches single instances of your pattern, so assuming it works and that we must use Notepad++ for this:
Replace .*?("id":.........,"kind":"track").*?(?="id".........,"kind":"track"|$) with \1.
If this textfile is valid JSON, this opens you up to other, non-notepad++ options, like using Python with the json module.
Edited to remove unnecessary steps

Remove all lines after an 4 digit number from a large number of .txt files

I have files that are split in two blocks, the first half contains the information I need, the second half always starts with a 4 digit number (between 1400 and 1900). I need to delete the second block, hence my question:
How do I delete all lines in a file after (and including) the first 4 digit number?
I believe that should be doable using notepad++ and regular expressions, but I'm new to regex and have no idea how...
I know it's a noob-ish question but nonetheless, help would be greatly appreciated.
The Regex 1(?:[4-8]\d\d|900)(?:.|[\r\n])+\z will select a text starting with 1400-1900 till the end of a file.

PowerShell isolating parts of strings

I have no experience with regular expressions and would love some help and suggestions on a possible solution to deleting parts of file names contained in a csv file.
Problem:
A list of exported file names contains a random unique identifier that I need isolated. The unique identifier has no predictable pattern, however the aspects which need removing do. Each file name ends with one of the following variations:
V, -V, or %20V followed by a random number sequence with possible spaces, additional "-","" and ending with .PDF
examples:
GTD-LVOE-43-0021 V10 0.PDF
GTD-LVOE-43-0021-V34-2.PDF
GTD-LVOE-43-0021_V02_9.PDF
GTD-LVOE-43-0021 V49.9.PDF
Solution:
My plan was to write a script to select of the first occurrence of a V from the end of the string and then delete it and everything to the right of it. Then the file names can be cleaned up by deleting any "-" or "_" and white space that occurs at the end of a string.
Question:
How can I do this with a regular expression and is my line of thinking even close to the right approach to solving this?
REGEX: [\s\-_]V.*?\.PDF
Might do the trick. You'd still need to replace away any leading - and _, but it should get you down the path, hopefully.
This would read as follows..
start with a whitespace, - OR _ followed by a V. Then take everything until you get to the first .PDF