Expounding on a RE isn't working

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
User avatar
kengrubb
Posts: 324
Joined: Thu Dec 11, 2003 5:23 pm
Location: Olympia, WA, USA

Expounding on a RE isn't working

Post by kengrubb »

I have a Macro that does an RE Replace. Keeps digits (0-9) plus CR and LF. It strips everything but digits from data.

Replace: [\x00-\x09\x0B-\x0C\x0E-/:-ÿ]
With: nothing

I'd forgotten how I made this happen, but fortunately I documented it in the Macro Description.

I tried to do this RE Replace, while it's keeping 0-9 and CR and LF, it is wiping out A-Z, which I want to keep.

Replace: [\x00-\x09\x0B-\x0C\x0E-/:-@\[-ÿ]
With: nothing

To keep from going blind, let me break it out. There are a series of ranges I'm trying to replace with nothing.

\x00-\x09
\x0B-\x0C
\x0E-/
:-@
\[-ÿ
(2[Bb]|[^2].|.[^Bb])

That is the question.
User avatar
kengrubb
Posts: 324
Joined: Thu Dec 11, 2003 5:23 pm
Location: Olympia, WA, USA

Post by kengrubb »

I also tried this, and it didn't work.

Replace: [\x00-\x09\x0B-\x0C\x0E-\x2F\x3A-\x40\x5B-\xFF]
With: nothing

\x00-\x09
\x0B-\x0C
\x0E-\x2F
\x3A-\x40
\x5B-\xFF
(2[Bb]|[^2].|.[^Bb])

That is the question.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You forgot about the lower-case letters.

Your character set expressions specify a set of characters that includes the lower-case letters (but not the upper-case letters).
So if Match case is selected they match lower-case letters (but not upper-case letters).
And if Match case is not selected they match both lower-case and upper-case letters.
If you want to use this technique to match neither lower- nor upper-case letters, you need to exclude both from the character set:
[\x00-\x09\x0B-\x0C\x0E-\x2F\x3A-\x40\x5B-\x60\x7B-\xFF]
which works whether Match case is selected or not.

But this is extremely obscure. It would be considerably clearer if you specifed explicitly what you don't want to match:
[^\n\r0-9A-Za-z]
User avatar
kengrubb
Posts: 324
Joined: Thu Dec 11, 2003 5:23 pm
Location: Olympia, WA, USA

Post by kengrubb »

Case. Knew it had to be something simple. Much appreciated.

Yes, the not match list is far easier to understand, but it's the not match list that I wish to keep while wiping out everything else.
(2[Bb]|[^2].|.[^Bb])

That is the question.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

[^\n\r0-9A-Za-z]
means any character that's not in
[\n\r0-9A-Za-z]
It's precisely what you need (and you've used it in your sig).
User avatar
kengrubb
Posts: 324
Joined: Thu Dec 11, 2003 5:23 pm
Location: Olympia, WA, USA

Post by kengrubb »

I'm tracking now. That IS much easier.
(2[Bb]|[^2].|.[^Bb])

That is the question.
Post Reply