Regexp: exclude a word or a phrase

Dear all

I am trying to exclude certain text from whole text using regular
expression but the i cannot get it working. I am using this to get the
text between the matches and not the match itself

for example, I have to process output of SVN DIFF and look through it

Index: filename1

···

==============
text
text
text
text
text
text
Index: filename2

text
text
text
text
Index: filename3

text
text

I want to count how many changed lines in each file, I am thinking of
getting the text between the lines of ========= which actually my target

i tried to use /[^=]+/ and it does not work because it will exclude
statements with equal signs as well which is not my aim

any idea

thanks
--
Posted via http://www.ruby-forum.com/.

I don't think I understand your intent, but in order to match
lines other than ones composed solely of =, try /^[^=]+$/

To match a location that does not contain a specific string, you
can try:

    /(?!foo)/

this regular expression will match a location that does not
contain the sequence "foo". Beware! Note that I'm writing
"location", not "string". This matches:

    "foo" =~ /(?!foo)/ )/ # anything not followed by foo, match

This also matches:

    "foobar" =~ /(?!bar)/ # anything not followed by bar, match

You have to anchor it somehow:

    "foobar" =~ /foo(?!bar)/ # "foo" not followed by "bar", no match

Marcelo

···

On Tue, Apr 20, 2010 at 07:29, Shuaib Zahda <shuaib.zahda@gmail.com> wrote:

i tried to use /[^=]+/ and it does not work because it will
exclude statements with equal signs as well which is not my aim

"Shuaib Zahda" <shuaib.zahda@gmail.com> wrote in message
news:1d6e0a96aa6e168091bdabb7c3fbf359@ruby-forum.com...

Dear all

I am trying to exclude certain text from whole text using regular
expression but the i cannot get it working. I am using this to get the
text between the matches and not the match itself

for example, I have to process output of SVN DIFF and look through it

Index: filename1

text
text
text
text
text
text
Index: filename2

text
text
text
text
Index: filename3

text
text

I want to count how many changed lines in each file, I am thinking of
getting the text between the lines of ========= which actually my target

i tried to use /[^=]+/ and it does not work because it will exclude
statements with equal signs as well which is not my aim

any idea

thanks
--
Posted via http://www.ruby-forum.com/\.

The regexp /^\=+$/ will match a whole line of '=' as in:

re = /^\=+$/
count = 0
section = 1
DATA.each_line do |row|
    if(re =~ row) then
        printf("section %d has %d records\n", section, count)
        count = 0
        section +=1
    else count +=1
    end # if
end # while
exit(0)
__END__
text1-
text2=
text3-

···

==========
text4
text5

Hth gfb