Help - Remove a line from a specific text but keep a part of the text
-
Hello community, help me to delete a specific line from a text but I want to keep a part of the text.
Example:
xxxxxxxxxx | dddddddddd = [aaaaaaaaaa, ssssssssss]
xxxxxxxxxx | dddddddddd = [aaaaaaaaaa, ssssssssss]
xxxxxxxxxx | dddddddddd = [aaaaaaaaaa, ssssssssss]
xxxxxxxxxx | dddddddddd = [aaaaaaaaaa, ssssssssss]I want to delete this pattern | dddddddddd = [aaaaaaaaaa, ssssssssss]
and keep the xxxxxxxxxx text.Thanks.
-
- FIND =
| dddddddddd = [aaaaaaaaaa, ssssssssss]
- REPLACE = empty
- Search Mode = Normal
- REPLACE ALL
If that’s not sufficient, you will have to describe your problem more accurately. The advice below will help you ask a better question.
----
Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as literal text using the
</>
toolbar button or manual Markdown syntax. To makeregex in red
(and so they keep their special characters like *), use backticks, like`^.*?blah.*?\z`
. Screenshots can be pasted from the clipboard to your post usingCtrl+V
to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get. Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries. - FIND =
-
@PeterJones Thanks, it works.
But the last value ssssssssss are different in all lines, how I remove them but keep the xxxxxxxxxx value?
-
@Daniel-Daniel said in Help - Remove a line from a specific text but keep a part of the text:
But the last value ssssssssss are different in all lines, how I remove them but keep the xxxxxxxxxx value?
You can use search mode = regular expression (aka, regex) instead of normal mode.
In regex mode, the [ and ] and | characters have special meanings, so you need to escape them.
But you don’t tell us any rules, and didn’t follow the advice of giving examples that should and shouldn’t match – ie, you ignored all of my advice above. So once again, you’re leaving us to guess what you want, which won’t likely get you to your solution very quickly.
But here’s a second guess as to what you want, and a solution that works for that guess: change the FIND to
\| dddddddddd = \[aaaaaaaaaa, .*?\]
and the Search Mode toRegular Expression
(and make sure “. matches newline” is off) – this will delete from the | onward , allowing anything but a newline to come after the comma and before the ] … If you really meant that thedddddddddd
,aaaaaaaaaa
, andssssssssss
can all be different, then just replace the others with.*?
as well… but at some point, it will probably be more generic than you intended.If this second guess doesn’t work for you, you will have to follow the advice you’ve already been given before I can do anything more to help.
-
@PeterJones Thanks for your help.
Alejandro Perez | Age = [20] | Sex = [Male] | Phone number = 3009876543
Carlos Gomez | Age = [20] | Sex = [Male] | Phone number = 3103457629I want to keep just the names, Alejandro Perez, Carlos Gomez, etc
And delete all the additional information | Age = [20] | Sex = [Male] | Phone number = 3009876543 as you can see, the phone number are variable.
-
Even easier:
- FIND =
\|.*$
- REPLACE = empty
- MODE = regular expression
- REPLACE ALL
If you had just said in the first place “I want to delete everything after the first | on any line (delete the | too)”, we would have gotten there a lot quicker.
- FIND =
-
@PeterJones Thanks, it works.
-
Hi,
I need to keep a group while moving it to the line above.
I have this:
WELLER,
IV, 3.I need this:
WELLER, IV, 3.
I tried this without success:
Find: \r\n(\sIV,)
Replace: ($0) -
@L-M said in Help - Remove a line from a specific text but keep a part of the text:
Replace:
($0)
$0
is the whole match. You should have used$1
if you wanted just the contents of group #1 from your match. -
@PeterJones Thanks it’s working now.
I also figured out some occurences had only the CR from this answer:
https://community.notepad-plus-plus.org/post/17010And could modify as this to accomodate:
Find: \r(\sIV,)
Replace: ($1)