Help Search

General questions about using TextPad

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

Post Reply
mpatel
Posts: 4
Joined: Tue Oct 24, 2006 2:22 pm

Help Search

Post by mpatel »

I wish to search for all lines of files which have a certain string say "ABCD" but want to ignore lines which have the FIRST non-space string as "--" (i.e the comment specifier). Can someone please say what the Regular Expression for this is.

Thankls
User avatar
meisn
Posts: 11
Joined: Wed Oct 18, 2006 6:25 pm
Location: Germany
Contact:

Post by meisn »

Hi,

If you want to search for a line which doesn't begins with a certain character use the negatived class followed after the a line anchor.

In your example this could look like the following:

^[^-]+.*$

(Using POSIX-Syntax)

Hope this could help you.

Regards,

Meisn
mpatel
Posts: 4
Joined: Tue Oct 24, 2006 2:22 pm

Post by mpatel »

Thanks, that works but not for lines which have "--" as the first non-blank string i.e I want to ignore lines which have "--" as the first non-blank string on the line. Thanks
User avatar
meisn
Posts: 11
Joined: Wed Oct 18, 2006 6:25 pm
Location: Germany
Contact:

??

Post by meisn »

Hi,

I can't understand what you're really looking for.
You wrote that you want to find lines which doesn't begin with '--' (which could be comments) - actually you wrote that you want to ignore them.

If you're using my suggested regex on the following SQL (in example)

^[^-]+.*$

you will find only those lines (line by line) which are marked in green:

--Test SQL--
select b.column_name, a.column_name from table1 a
join table2 b
on b.column_id = a.column_id
where 1=1
and a.column_name like 'abc'

-- and b.column name in ('bc','cd')
--order by 1,2

As you can see the regex "ignores" the commented lines.

If this doesn't fit, please specify your problem a bit further.

Regards,

Meisn
mpatel
Posts: 4
Joined: Tue Oct 24, 2006 2:22 pm

Post by mpatel »

I only want the Search to find the lines listed in the SQL test which are in green. I have put <space> and <tab> markers in the text to mean that they are spaces or tabs as this forum seems to remove leading spaces in lines. Thanks for all your help


--Test SQL--
select b.column_name, a.column_name from table1 a
join table2 b
on b.column_id = a.column_id
where 1=1
and a.column_name like 'abc'

-- and b.column name in ('bc','cd')
--order by 1,2
<space><space><space>-- HHHH
<tab><tab><space>-- YHYH kk
<tab>-- TGTG
abcdef
User avatar
meisn
Posts: 11
Joined: Wed Oct 18, 2006 6:25 pm
Location: Germany
Contact:

Post by meisn »

Hi,

could you please try this one. It will also ignore any whitespaces.

^[^-[:space:]]+.*$

Regards

Meisn
mpatel
Posts: 4
Joined: Tue Oct 24, 2006 2:22 pm

Post by mpatel »

Yes, that works except for the case where a non-comment line has spaces before the code. Try this (replace <space> and <tab>) and note that it does not find the lines in red. Thanks for all the help

--Test SQL--
select b.column_name, a.column_name from table1 a
join table2 b
on b.column_id = a.column_id
where 1=1
and a.column_name like 'abc'
-- and b.column name in ('bc','cd')
--order by 1,2
<space><space><space>-- HHHH
<tab><tab><space>-- YHYH kk
<tab>-- TGTG
<tab><space> not a comment line1
<tab> not a comment line2
<space><space> not a comment line3

abcdef
User avatar
meisn
Posts: 11
Joined: Wed Oct 18, 2006 6:25 pm
Location: Germany
Contact:

Please try this

Post by meisn »

^[^-]?[^-]+?$

It should match only uncommented lines.

Cheers

Meisn
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Re: Please try this

Post by ben_josephs »

meisn wrote:^[^-]?[^-]+?$
That's equivalent to ^[^-]*$, which just matches all lines containing no hyphens; so it doesn't match non-comment lines containing innocent minus signs.

The problem is to find all lines in which either the first non-space character or the character after that is not a hyphen, and which contain ABCD. This can only be done clumsily in TextPad. If the ABCD doesn't start at the first or second non-space character of a line, this should do it:

^[[:space:]]*([^-[:space:]]|[^[:space:]][^-]).*ABCD

If the ABCD can start at the first or second non-space character, it gets far horribler.

The job can be done much more simply, and without the restriction on where ABCD can occur, in WildEdit (http://www.textpad.com/products/wildedit/):
Find what: ^(?![[:space:]]*--).*ABCD

[X] Regular expression

Options
[X] '.' does not match a newline character
Post Reply