I'd like to add a text of line after a specific line in Notepad++ I have found several similar answers through the web but I couldn't manage to adapt the code without recurring.
This is how my text file displayed in Notepad++
This is sample 1
This is sample 2
This is sample 3
This is sample 4
This is how I want it displayed after applying regex (Find third row, Insert the text without deleting any other line):
This is sample 1
This is sample 2
I insert the text here
This is sample 3
This is sample 4
The code should not search for any word to get a reference point except counting rows until find the specified one. In addition, it shouldn't repeat in the same text file like "every X row". I'd really wonder how it's done inside a batch file but a regex preferable for me.
Thanks in advance.
Just change {3} to {2}to match 2 lines.
Find what: (?:.+\R){2}\K
Replace with: Insert this sample\n
Related
A colleague has inserted duplicates for ~1200 entries into our database. They have sent me a text file containing both the originals and copies in alternating lines of CSV text. I've opened that up in VS Code with the goal of converting the lines representing duplicates into DELETE statements targeting our database. No line is truly identical to another—every two is a pair in which the data is the same other than the row ID.
I have found Stack Overflow entries for removing every other line when the line is empty, or when every other line is an exact copy of the previous line. I have not found an entry this scenario in which the lines have a difference. E.g. I tried using (.*)\n\1 w/ $1\n from another SO entry, which seems to target truly duplicate lines.
So how do I use VS Code to delete every other line regardless of content?
You can achieve this using Replace-All UI in regex mode.
Press command-F or control-F
Expand the arrow on the left of the Find display
Press the ".*" so that it's highlighted
Enter this for Find (top text field in the Find UI): (.*\n)(.*)\n (basically select two lines but save the contents of the first line in the regex system)
Enter this for Replace (following text field in the find UI): $1 (take the line saved from the Find regex and re-insert it)
Hit the Replace All button
Here's a similar SO question
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
I am trying to validate a csv file using Apache-NiFi.
My CSV file has some defects.
id,name,address
1,sachith,{"Lane":"ABC.RTG.EED","No":"12"}
2,nalaka,{"Lane":"DEF",
"No":"23"}
3,muha,{"Lane":"GRF.FFF","No":"%$&%*^%"}
Here in second row,its been divided into two lines and third row has some special characters.
I want to ignore both the lines. For that I use \{("\w+":"\w+",)*[^%&*#]*\}, but this is not capturing row split error and new line.
I also used \{("\w+":"\w+",)*[^%&*#]*\}$, but it doesnt even get the right answer.
This is you might looking for: ^[0-9]+,[a-z]+,\{("\w+":"[\w\.]+","\w+":"[a-zA-Z0-9]+")\}$
I have this line in more then 1000 .php files. The number in every file is different, from 500 to 1000.
$item_id = 752;
In some files, some numbers are repeated and I don't know what are those numbers.
Can anyone give me a solution? A regex or a .php script, maybe..??
You could use a simple regex search like this:
\$item_id = \d{3,4};
Working Example
Note that this will match any lines that have numbers with 3 or 4 digits, if you specifically need the range 500-1000 that would work a little differently
I find a very simple and good answer. First open a text_editor, I am using GrepWin.
Step 1: Search this Regular Expression: \$item_id = \d{3,4}; (This will show the results from every page)
Step 2: Select all results -> Right click -> "Copy filenames to clipboard" and "Copy text results"
Step 3: Open Excel. On the A columns, select cells and copy those filenames, and in the B column, select cells and copy text results (Only the numbers).
Step 4: From excel: DATA-> remove duplicates
Super Easy. Thank you jjspace for the 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