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
Help Search
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
??
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
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
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
--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
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
--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
^[^-]?[^-]+?$
It should match only uncommented lines.
Cheers
Meisn
It should match only uncommented lines.
Cheers
Meisn
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
Re: Please try this
That's equivalent to ^[^-]*$, which just matches all lines containing no hyphens; so it doesn't match non-comment lines containing innocent minus signs.meisn wrote:^[^-]?[^-]+?$
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