regular expression and negated class expressions

General questions about using TextPad

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

Post Reply
aaronfinch
Posts: 3
Joined: Tue Apr 29, 2003 6:58 pm

regular expression and negated class expressions

Post by aaronfinch »

Hi, Can't seem to find what I'm trying to do. I build large text files and wish to Find lines of text that have certain characters but don't have others. I've played with the negated class expressions but can't get it quite to what I want. For example: I have a file with a bunch of lines saying "Message Num: XXX" and the XXX can be a 1 digit number or any 3 digit number. Now I know many of them will be "Message Num: 68". But there might be a few that are 681 or 17 or 3 or some other unknown 3 digit number. The ones that are not 68 are the ones that I want to bookmark so that I can find them. The negated class expression will see that first 6 and not care about the rest of the number. I need some sort of logical AND operator. The search string would have to match the "Message Num: " AND the first digit is not 6 WHILE the second digit is not 8 WHILE it is just a two digit number.
Sorry if this explanation seems lacking. Can anyone help?
Aaron
aaronfinch
Posts: 3
Joined: Tue Apr 29, 2003 6:58 pm

invert all bookmarks

Post by aaronfinch »

I did figure a roundabout way to do this. Does work. Not sure if I can build a macro to do it though. First do a search on "Message Num: " and Bookmark All. Then invert all bookmarks. Then do a search for the same string with the number I don't want - "Message Num: 68" and bookmark all of them. (That's the part I'm not sure how to record as a macro). Then do another invert all bookmarks. Any better solutions out there?
Aaron
User avatar
Bob Hansen
Posts: 1517
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

:?I am confused about your lines. You say:
I have a file with a bunch of lines saying "Message Num: XXX" and the XXX can be a 1 digit number or any 3 digit number. Now I know many of them will be "Message Num: 68". But there might be a few that are 681 or 17 or 3 or some other unknown 3 digit number.
But the example you give is a 68 which is two digits, then you mention 17 or 3 which are also not three digits.

:?:
1. Is 68 a three digit figure counting a blank space in front?
2. Is 68 a three digit figure counting a blank space behind?
3. Is 68 really a two digit figure?
4. Is the number really a one, or a two, or a three digit number? Any one of them may appear?
5. Are the quotes around the string as shown?
6. What character would follow the last digit? A double quote?

Then you summarize with:
The search string would have to match the "Message Num: " AND the first digit is not 6 WHILE the second digit is not 8 WHILE it is just a two digit number.
This sounds like you are looking for any two digit number which is not 68.

Summary: Search for "Message Number: xx" where xx is not equal to 68. Also accept any single digit, three digit numbers. Still would like to know about the "quotes" and what character or space or line return or symbol etc. might be expected to follow immediately after the last digit (whether 1 or 2 or 3 digits long).

Sorry if this confuses you, but you have confused me! :D
Hope this was helpful.............good luck,
Bob
Guest

clarification

Post by Guest »

Sorry for the confusion, Bob.
Questions 5 and 6 -> no quotes
The other 4 questions: The number can be any 3 digit value or any 2 digit value or any 1 digit value. There is a space after the colon but it's only purpose is to separate the colon from the number - it is not a placeholder for a digit.
The value of 68 is just an example. I might wish to bookmark all Message Nums that are not 3 or 989 or whatever.
Oh and after the last digit a carriage return is expected.
Hope this helps.

Aaron
Guest

Post by Guest »

Aaron,

A correct regular expression to exclude a certain string is not very pretty.

To exclude "681", you can want to match 3 digit numbers that don't start with a six:
[012345789][0-9][0-9]

Also, starts with a 6 but the next number isn't an 8:
6[012345679][0-9]

Also, starts with a 68 but doesn't end with a 1:
68[023456789]

All together, matches any 3 digit number except "681":
[012345789][0-9][0-9]\|6[012345679][0-9]\|68[023456789]

To also match 1 or two digit numbers, you need to add more ORs to the regular expression.
User avatar
Bob Hansen
Posts: 1517
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Hi Aaron.....you mentioned:
That's the part I'm not sure how to record as a macro
If always looking to do this for error 68, that is not a problem, I just made a macro to do that (See steps below). But it canot be done for an on-the-fly user-selected characters, line, clipboard value.

You can't make a macro in TextPad to do this search for a generic value. When TextPad records the macro using a Find or Replace for a string, it actually records the value used at that time, even if it comes from the clipboard. So you would have to make a separate macro for every error code you wanted to process.
=========================
Here are the steps to make a macro to bookmark all lines that not like the line that is selected:
Macro Preparation before running:
Place cursor on line to be MIS-BookMarked

Macro Steps to be recorded and played back:
Clear all bookmarks (ALT-S-C)
Highlight line to be "Mis"bookmarked (Home,SH-End)
Search,Find,(F5)
Insert Return code(\n), Mark All (Alt-M)
Close FindWindow (SH-Tab-2x, Enter)
Search, Invert bookmarks (ALT-S-A)
Go to top of document (CTL-Home)
Regular expressions may be too awkward without ability to do LookAheads. Previous message from Guest was good example.

I have asked for a clarification about the LookAhead/LookBehind Regex capability in TextPad in a separate Subject.

Hope this helps.
Hope this was helpful.............good luck,
Bob
aaronfinch
Posts: 3
Joined: Tue Apr 29, 2003 6:58 pm

Post by aaronfinch »

Thanks guys for your help. Wow that is a scary looking regex! I guess macros will get me closest to what I want.
Post Reply