Search for > in column 1

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
Mach1
Posts: 4
Joined: Wed Sep 03, 2008 10:42 am
Location: UK

Search for > in column 1

Post by Mach1 »

Is there any way to search for > followed by a space, but ONLY in column 1 of a file? I have tried various permutations following suggestions in the help file, so far without success.

Regards

Mach1
ACRobin
Posts: 134
Joined: Fri Nov 04, 2005 9:51 pm
Location: Northumberland,UK
Contact:

Post by ACRobin »

"^[>[:blank:]]"
The above (minus the quotes) is the regular expression you will need in the Find box (regular expression - ticked).

I am no expert, but seems to work.
Mach1
Posts: 4
Joined: Wed Sep 03, 2008 10:42 am
Location: UK

Post by Mach1 »

I am confused! :(

I tried your suggestion, but it seemes to find any line starting with a blank. So I played around a bit and found that this works: ^>[>[:blank:]]

I am an absolute beginner on this topic and do not understand what the different elements of the expression signify - but I appear to need BOTH > symbols to get this working.

Can anyone offer a beginners source that gives a little explanation of the syntax?

Thanks.
ak47wong
Posts: 703
Joined: Tue Aug 12, 2003 9:37 am
Location: Sydney, Australia

Post by ak47wong »

ACRobin wrote:"^[>[:blank:]]"
The above (minus the quotes) is the regular expression you will need in the Find box (regular expression - ticked).
This isn't correct. That matches either ">" or a space or a tab at the start of the line, not what Mach1 was asking for.

The correct expression is: ^>_
where _ represents a space.

Make sure "Regular expression" is ticked in the Find dialog.

Andrew
Mach1
Posts: 4
Joined: Wed Sep 03, 2008 10:42 am
Location: UK

Post by Mach1 »

VERY confused now... But the good bnews is that both my own variant of ACRobin's suggestion AND that fro Andrew seem to work....So although I don't understand why - my immediate problem is solved.

Thanks to you both for very prompt (and helpful) responses.

Mach1
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Your regular expression is incorrect.

^>[>[:blank:]] matches

Code: Select all

^             the beginning of a line
>             the literal text: >
[>[:blank:]]  either a > or a blank
Thus it matches on lines that begin with with a >, followed by either a another > or a blank. So it matches, for example, on lines that begin
>>xxxx

As Andrew suggested, you can use a simple space instead of the cumbersome expression [:blank:], unless the > might be followed by a tab instead of a space (in which case [ \t] is shorter).

There are many regular expression tutorials on the web, and you will find recommendations for some of them if you search this forum.

A standard reference for regular expressions is

Friedl, Jeffrey E F
Mastering Regular Expressions, 3rd ed
O'Reilly, 2006
ISBN: 0-596-52812-4
http://regex.info/

But be aware that the regular expression recogniser used by TextPad is very weak compared with modern tools. So you may get frustrated if you discover a handy trick that works elsewhere but doesn't work in TextPad.
Mach1
Posts: 4
Joined: Wed Sep 03, 2008 10:42 am
Location: UK

Post by Mach1 »

Thanks for the tips. The help you have all provided has been a great asssistance with what was promising otherwise to be an extremely tedious (and probably error-prone) task.

Regards

Mach1
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You're welcome.

I see that my message might mislead, so I should add a clarification:

[ \t] is equivalent to [[:blank:]] and [> \t] is equivalent to [>[:blank:]].
Post Reply