Regex to match mutliple patterns of copyright statements

I am new to regex. I have written regex to identify any pattern of copyright statement but it has many conditions and could match only in certain cases. Also need to validate for correct statement after matching the statements. All the following words to be matched no matter where it is found in a file. For example:

Copyright xyz

(c) abc

Copyright xyz@any.com

Copyright (c) www.arm.com

Copyright (c) ABC www.abc.com. all rights reserved.

(c) copyright ABC. All rights reserved. abc@any.com

Copyright © 2009 Mar FGH. All rights reserved.

(c) 2009-2020 sdf ltd. All rights reserved.

© xyz all rights reserved.

and many patterns like this in different variations.

Please check my regex here:

https://regex101.com/r/NT0c9v/1

(?:©(?:\s*Copyright)?|Copyright(?:\s*©)|\(C\)(?:\s*Copyright)|Copyright(?:\s*\(C\))?)|(?:\(C\))|\s*\d+(?:\s*-\s*\d+)?\s*(.*?(?:\W*All\s+rights\s+reserved)|[^.\n]*(?=\.)|.*)|([a-zA-Z0-9-_.]+@[a-zA-Z0-9-_.]+)

Please help me to fetch all matches. I am stuck somewhere not knowing what.

Solution to this will be highly appreciated.

0 1 314
1 REPLY 1

Yep,

that's a bit of a hairy problem. Have you ever heard the saying?

Some people, when confronted with a problem, think
“I know, I'll use regular expressions.” Now they have two problems.

Attributed to Jamie Zawinski.

I don't have a ready solution for you. But I do have a suggestion:

Don't try to solve this with a single regex. If I were solving this problem I would want to use multiple distinct regex for each of the many various cases you presented. For more background on that suggestion, I suggest you read the Coding Horror blog post. This is really a regex special case of the general aphorism: when you have a complex problem, try breaking it down into smaller, solvable units.

So, find the regex for

Copyright xyz@any.com

...

Then, find the regex for the next form. And the next. And so on.

And then you can just use a logical OR - if any of the regex match, then you. have a copyright notice.

If you need help with the smaller regex, Maybe you could try asking on Stackoverflow for some assistance?