Find

General questions about using TextPad

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

gcotterl
Posts: 248
Joined: Wed Mar 10, 2004 8:43 pm
Location: Riverside California USA

Find

Post by gcotterl »

How can I find rows with a decimal-point at the 58th position?
bveldkamp

Post by bveldkamp »

Code: Select all

Find what ^.{57}\.
[X] Regular Expression
(POSIX regular expressions assumed)
gcotterl
Posts: 248
Joined: Wed Mar 10, 2004 8:43 pm
Location: Riverside California USA

Find

Post by gcotterl »

What would your example be if I'm looking for a comma in position 23?
User avatar
talleyrand
Posts: 624
Joined: Mon Jul 21, 2003 6:56 pm
Location: Kansas City, MO, USA
Contact:

Post by talleyrand »

The general form would be

Code: Select all

Find what ^.{N-1}\.
where N is the position.

Note, you must do the math and not put 58-1 or 23-1
I choose to fight with a sack of angry cats.
gcotterl
Posts: 248
Joined: Wed Mar 10, 2004 8:43 pm
Location: Riverside California USA

Find

Post by gcotterl »

Your example contains TWO periods.

^.{N-1}\.

Which one is the "Find" character?
gcotterl
Posts: 248
Joined: Wed Mar 10, 2004 8:43 pm
Location: Riverside California USA

Find

Post by gcotterl »

I re-read the postings and noticed the reference to "POSIX regular expressions assumed".

I clicked on CONFIGURE/PREFERENCES/EDITOR and clicked on "Use POSIX regular expressions syntax".

It's now working!!

Thanks loads! This will save me many hours of work!!
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

That was a slip.

It should be
Find what: ^.{N},

[X] Regular expression
where N is one less than the column position.

In your case:
Find what: ^.{22},

[X] Regular expression
In the search text, when you are searching using a regular expression, a simple dot ( . ) represents any single character (except newline); a quoted dot ( \. or [.] ) represents a literal dot.

This assumes you are using Posix regular expression syntax:
Configuration | Preferences | Editor

[X] Use POSIX regular expression syntax
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Re: Find

Post by ben_josephs »

gcotterl wrote:"Use POSIX regular expressions syntax"
In this example, it's just the braces ( {...} ) that are affected. The meanings of {...} and \{...\} are swapped.
gcotterl
Posts: 248
Joined: Wed Mar 10, 2004 8:43 pm
Location: Riverside California USA

Post by gcotterl »

What would be the "Find What" entry for finding a dash (i.e., "-") in position 77?
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Have a look through the preceding messages and try to find a pattern.
gcotterl
Posts: 248
Joined: Wed Mar 10, 2004 8:43 pm
Location: Riverside California USA

Post by gcotterl »

Hi Ben,

It looks like the character that I want to find follows the ^

So:

To find a dash, the entry would be: ^-{N},

To find an "BC", the entry would be: ^BC{N},

To find any single character (except newline), the entry would be: ^.{N},

To find a literal dot, the entry would be" ^\.{N}, or ^[.]{N},


correct?



I don't know what you mean by "In this example, it's just the braces
( {...} ) that are affected. The meanings of {...} and \{...\} are swapped).
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

No. To find lines with a hyphen in position 77, you need: ^.{76}-

Code: Select all

^        beginning of a line
.        any character
.{76}    any character, 76 times; i.e., any 76 characters
^.{76}   any 76 characters at the beginning of a line
-        a hyphen
^.{76}-  any 76 characters at the beginning of a line, followed by a hyphen
To find lines with a dot in position 77, you need: ^.{76}\.

By "The meanings of {...} and \{...\} are swapped" I meant that they have opposite meanings in Posix and non-Posix syntax.

Edit: Added missing hyphen in last line of explanation.
Last edited by ben_josephs on Tue Mar 21, 2006 4:34 pm, edited 1 time in total.
gcotterl
Posts: 248
Joined: Wed Mar 10, 2004 8:43 pm
Location: Riverside California USA

Post by gcotterl »

So the character I want to find follows the last brace (instead of the ^). Right?
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

I think that a more effective way for you to learn how to use regular expressions might be for you to try to understand how they are constructed, rather than repeatedly relying on others to give you a new expression each time there is a small change in your requirements.

If there is anything in the explanation I gave earlier that is not clear, please let me know, and I will try to express it more carefully.
gcotterl
Posts: 248
Joined: Wed Mar 10, 2004 8:43 pm
Location: Riverside California USA

Find

Post by gcotterl »

(I'm sorry for the questions but I just want to understand the syntax of the expression so I can use it correctly).

Your previous posting says:
To find lines with a hyphen in position 77, you need: ^.{76}-
To find lines with a dot in position 77, you need: ^.{76}\.

So, I was correct in saying that "the character I want to find follows the last brace (instead of the ^)".

In your second example above:
}\. looks for a single DOT
}. looks for ANY character (except newline).
Post Reply