Page 1 of 1

Replace tabs/spaces NOT at beginning -or- end of the line

Posted: Wed Dec 10, 2014 9:41 pm
by no.cache
I have no problem trimming the dead space at the beginning or end of a line; this thread is when random line-lengths of text contain dead space/tabs in the middle of a line of text.

These strategies in Textpad don't work (but that's no big deal because I've never gotten them to work lol):
[:blank:]
[:space:]
[:print:]

Using @ as a placeholder for 1 space, this is the bad boy I hoped would work:
@@{2,}

The idea is to tighten up dead spaces/tabs in the middle of a line by either replacing them with something (example YY) or deleting them altogether.

I've even tried this with "Regular expression" unchecked. No joy. So . . .

Since I want this search/find/replace string to be durable, I'd like it to apply to anything alpha, numeric, symbol, glyph etc. no matter what kind of symbol, globally.

Thanks guys.

Posted: Thu Dec 11, 2014 12:19 pm
by MudGuard
Your expression @@{2,} means:
@
find one @
@{2,}
find at least 2 @ (or more, if there are more).

Together:
@@{2,}
find at least 3 @ (or more).
This is identical to
@{3,}

you probable want
@{2,}

Posted: Wed Dec 17, 2014 6:19 pm
by no.cache
Cannot find regular expression:

Code: Select all

@@{2,}
Cannot find regular expression:

Code: Select all

@[2,]
Cannot find regular expression:

Code: Select all

@{2,@}
See what I mean MG? :roll: And it's always been like this for me. Very Frustrating!!

Posted: Wed Dec 17, 2014 7:53 pm
by MudGuard
SKYE McLAUGHLIN wrote:
Cannot find regular expression:

Code: Select all

@@{2,}
I already explained this one before ...
SKYE McLAUGHLIN wrote:
Cannot find regular expression:

Code: Select all

@[2,]
This matches @2 or @,
as [2,] matches one character that is either a 2 or a comma.

SKYE McLAUGHLIN wrote:Cannot find regular expression:

Code: Select all

@{2,@}
I am not sure whether a space is allowed between , and }
Thus, this is either invalid (not a regex), or it is the same as @{2,}

Btw, why do you use that extremely old 5.0.3?

Posted: Wed Dec 17, 2014 10:01 pm
by no.cache
The example I gave with braces [ instead of brackets { was a typo on my part. Here it is corrected:
Cannot find regular expression:

Code: Select all

@{2,}
At no time should you feel that I am challenging your expertise MudGuard. You remain one of a small handful of coding experts whose advice I have greatly benefited from over the years. Your advice is unimpeachable and as I have thanked you many, many times before, I thank you once again. If there were a way I could upload a screenshot of each of these rejected attempts I would because I am painfully aware that you must think I'm off my nut :oops: That makes two of us!

I'm going to spell out the string you recommended above:
you probable want

Code: Select all

space
left.bracket
number.2
comma
right.bracket
If that is the exact string it does not work. I'm still on 5.0.3 because when I attempted to upgrade to 7 it was rife with errors and instability. I've never had a problem with 5.

Posted: Wed Dec 17, 2014 10:09 pm
by no.cache
I wonder . . . could this be something I have altered in Textpad's Preferences? because this is the second time that search strings I've researched in Textpad's help file do not work with any of these braced expressions:

[:blank:]
[:space:]
[:print:]

Posted: Wed Dec 17, 2014 11:39 pm
by ben_josephs
Those character class expressions are enclosed by (square) brackets, not (curly) braces. And they can be used only within character sets, which are themselves enclosed by (square) brackets, like this:
[[:blank:]]
[[:space:]]
[[:print:]]

The expression [:blank:] not within brackets matches any one of the characters
: (colon), b, l, a, n, k.

Have any of your regexes acquired unwanted spaces at their right-hand ends?

Posted: Thu Dec 18, 2014 2:46 am
by no.cache
ben_josephs wrote:The expression [:blank:] not within brackets matches any one of the characters
: (colon), b, l, a, n, k.

Have any of your regexes acquired unwanted spaces at their right-hand ends?
Wow, did I have that one wrong. :oops: I couldn't tell you about trailing spaces because I've avoided braced expressions altogether when, years ago, I could never get them to work. I thank you Ben. I'll add it to my Textpad notes. May I just confirm one other thing? Are you telling me that the following example of double braces — [[:space:]] — finds a space?

Posted: Thu Dec 18, 2014 9:28 am
by ben_josephs
These are braces: { }
These are brackets: [ ]
Character sets (as in [abc] ) and character classes (as in [:space:] ) are enclosed in brackets, not braces.
Bounded repetition operators (as in @{2,}) are enclosed in braces, not brackets.

Did you try a regex search using [[:space:]] ?

Posted: Fri Dec 19, 2014 9:09 pm
by no.cache
ben_josephs wrote:These are braces: {}
These are brackets: []
Well. There go me and 170 million other people¹ (and George Gershwin² oddly enough).


:P
¹Google { and Bracket
²http://en.wikipedia.org/wiki/wiki/Let's_Call_the_Whole_Thing_Off

Posted: Sat Dec 20, 2014 12:29 am
by ak47wong

Posted: Wed Dec 24, 2014 12:25 am
by no.cache
ben_josephs wrote:Did you try a regex search using [[:space:]] ?
Yes Ben and that exact string works for locating one space/tab etc. Everyone on the forum has been so helpful to me, and I just can't get it to work.

It is such a simple thing:
Find 2 or more spaces or tabs.


I should be able to find it in Textpad Help. I can't.
I should be able to Google it if (for whatever reason) the examples given on the forums here aren't working.

Every site I've visited hoping to see an explicit example either has examples for 1 space/tab . . . or buried in a string so complicated my eyes glaze over.

I can get @@+ to work, but only on spaces. Is there a way I can get it to match either spaces or tabs? I'm sorry, I know you are all trying to help me. :(

Posted: Wed Dec 24, 2014 6:10 am
by ak47wong
SKYE McLAUGHLIN wrote:It is such a simple thing:
Find 2 or more spaces or tabs.
Any of the following will do it:

[@\t][@\t]+
[@\t]{2,}
[[:blank:]][[:blank:]]+
[[:blank:]]{2,}


The pattern \t matches a tab, so [@\t] matches a space or a tab.
The character class [:blank:] matches a space or a tab (if used within a character set like [[:blank:]] as ben_josephs explained above).
These are listed in the help file under Tabs and Character Class Operators respectively.