What is a regular expression for matching a line of text that contains "Copyright"?

760 Views Asked by At

I'm attempting to create a regular expression to use as a filter in DeltaWalker. I want to identify the files that had code updated in a library that our project uses, but the library source files have all had a single line, Copyright (c) 2008 - 2009 changed to Copyright (c) 2008 - 2010. I'd like to ignore those lines because otherwise most files contain the same source code.

3

There are 3 best solutions below

1
On BEST ANSWER
^.*Copyright.*$

matches an entire line if it contains the word Copyright.

^(?:(?!Copyright).)*$

matches an entire line if it does not contain the word Copyright.

Which one you need to use depends on how filtering works in DeltaWalker.

EDIT: If you only want to match lines that follow the specific format you quoted, then you could use

^\s*Copyright\s*\(c\)\s*\d+\s*-\s*\d+\s*$
0
On

If you're not wanting the 2010 stuff, you can do this.

^.*Copyright \(c\) 2008 - 2009.*$

0
On

Don't know much about DeltaWalker, but this regexp should will match both "Copyright (c) 2008 - 2009" and "Copyright (c) 2008 - 2010"

/Copyright \(c\) 200(8|9) - 20(09|10)/

You can try out different regular expressions easily with this site:

http://www.rubular.com