Delete text up to a certain number of characters from the end of a line
-
I’ve tried a few different regex strings, but can’t figure out the lookahead part to make this work. I have a few thousand lines of text and am trying to remove the variable number of characters and leave a fixed number of them from the end of the line. Examples:
Input:
alhsoidoli aoisudoifu oaisoi
iodaoiu a;osidh ;oaiyu ;oisdlhidadsli
LOIHYoihdlhi OIHlohi LOHIOOLhiol ooOutput:
ifu oaisoi
dlhidadsli
OOLhiol ooSo the find criteria would match the last 10 characters from the end and preserve that, deleting the entire rest of the line. I don’t have any special delimiting character I can match on; every line is very different. The only thing I do know is the fixed number of characters from the end of the line. Thanks!
-
My logic would be “capture from the beginning of the line, as many characters as possible, until a lookahead of 10 characters before the EOL is matched”. That translates into something like:
- FIND =
^.*(?=.{10}$)
REPLACE = empty
MODE = regular expression
Which worked for me
ifu oaisoi dlhidadsli OOLhiol oo
If this doesn’t work for you, you will have to clarify, after reading and taking to heart the following advice:
----
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 plain text using the
</>
toolbar button or manual Markdown syntax. 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 =
-
That worked like a champ! Thank you ever so much!