Page 1 of 1
Help Search
Posted: Tue Oct 24, 2006 2:32 pm
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
Posted: Tue Oct 24, 2006 4:12 pm
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
Posted: Wed Oct 25, 2006 8:23 am
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
??
Posted: Wed Oct 25, 2006 10:47 am
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
Posted: Wed Oct 25, 2006 10:58 am
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
Posted: Wed Oct 25, 2006 1:57 pm
by meisn
Hi,
could you please try this one. It will also ignore any whitespaces.
^[^-[:space:]]+.*$
Regards
Meisn
Posted: Wed Oct 25, 2006 2:14 pm
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
Please try this
Posted: Wed Oct 25, 2006 3:53 pm
by meisn
^[^-]?[^-]+?$
It should match only uncommented lines.
Cheers
Meisn
Re: Please try this
Posted: Sat Oct 28, 2006 5:34 pm
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