is there a REMOVE UNNECESSARY BLANK only (not EOL also)?
-
Is there any way to run only the “remove unnecessary blank” (Edit\Blank Operations), but leave off the “and EOL” part?
I find I’m dealing with lots of text that has extra spaces mixed in. Looking for a quick way to expunge them. But not the EOL’s.
Maybe via a plugin?
If not that (gulp), then dare I ask for someone to toss me a regex line?
Thx. - Chris -
@Chris-Tanguay-0 said in is there a REMOVE UNNECESSARY BLANK only (not EOL also)?:
If not that (gulp), then dare I ask for someone to toss me a regex line?
Well, you are right to ask as the “built-in” option will indeed do extraneous blanks and EOLs all in one swipe. Your request is not an option using the built-ins, perhaps it could be. To do so that would require a feature request, which would need to be placed on github, more details on how to do so are here, in our FAQ section.
But to get back to the question in hand. Looking back over your other posts I see you have asked quite a few questions and have been requested to start helping yourself by reading up on regular expressions. This particular question is one that a beginner should be able to figure out, but I will at least help out a bit.
For most questions I usually start of by writing (or thinking) in English what my steps would be. the actual “programming” is the very last step and if the “English” is logical the programming is generally achieved within a couple of tries. So what would be the process in English, well:
- Find a blank space
- look ahead and see if another exists, if so remove.
This seems good for 2 blanks, but what about more than 2 together? Well, we adjust the process so that we:
- Find MANY blank spaces together
- return ONLY 1 blank space
At this point I’d be happy with the process and I’d create the regex. I’ll leave that step up to you.
Terry
-
@Chris-Tanguay-0 Your request would benefit from being less ambiguously specified. Presuming “Trim leading and trailing” doesn’t satisfy your need, are you clear about whether you want every run of 2 consecutive spaces deleted? collapsed into a single space?
-
@Terry-R
Thanks for your thoughtful and linear reply. Have I had the time I really need to dedicate – to sitting down a few hours each day, with the regex walk-through sites, playing, toying, testing, tinkering? Getting better at it a little bit at a time? I guess shamefully, not even close. Life has been dealing me a whopper of a meal as of late. I do realize, given time, I could master pretty much every nook and cranny of regex. But not likely to happen until early winter… like maybe Mid December, when we have our short shutdown period where i work. That’s when I’ll get a first chance to actually take a breath. All my posts have come from work context… were I live and love my NP++.
Is there any kind of regex reference site that has an AI type search… where I could type in what I’m looking to do, and it takes me to ‘closest matches’? Can you hear my angst? Ha!
Anyway, to answer what Neil was asking… I’m only talking about text sentences. Like this example:
So, no real leading or trailing space issues ever in my examples. I just need to convert any 2 or more consecutive spaces found, into 1 space. It could be 2 spaces, or it could be 50 spaces. Totally random. ANd that includes between period and next character.
So, to answer your question, it could be either 2 spaces, or many spaces.
I could create one of those pipe expressions like this (and put it into a macro):
… where each pipe is incrementally higher # of spaces (2,3,4,5,6,7,8,9,10)…
and replace all of those with a single space…
But that only covers me through 10 consecutive spaces…
Hey, at least I’m trying to think outside the box!
Sorry to all if my collective posts have been a bit of a nag. -
This post is deleted! -
@Chris-Tanguay-0 said in is there a REMOVE UNNECESSARY BLANK only (not EOL also)?:
I just need to convert any 2 or more consecutive spaces found
FIND =
\x20+
(this could be space-plus,+
)
REPLACE =\x20
(this could be a single space)
SEARCH MODE = regular expression\x20
is a way of representing the space character that is easy to read/copy/paste from the forum; I mention both for ease of use. So if you’re typing, just type the characters for space and plus in the SEARCH dialog; if you’d rather copy/paste, it’s probably better for the \x20 version.BTW: this is what @Terry-R was hinting at, suggesting that you could easily figure out how to use regular expressions to search for more than one space and convert it to a single space… because that’s about the simplest modifier (
+
) in regular expressions.It will behoove you to start learning this on your own.
----
Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will often give help on the first one or two data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.
----
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.