I'm considering using a nontrivial Regex expression example I found online in a commercial product. The original page has no info on licensing.

I guess a regex is arguably executable code (or a court instance could be persuaded in this direction).

Do you know any examples of copyrighted regex expressions (or any counter-example to regexes being covered by a license)?

  • 5
    I'm voting to close this question as off-topic because this is not about open source at all but a law question about what can be copyrighted. Thus it belongs to Law SE and should be migrated there.
    – Zimm i48
    Mar 27, 2017 at 11:43
  • 1
    Rule of thumb: If you consider it worth copying (over making it yourself) it is likely non-trivial enough to be eligible for copyright.
    – Philipp
    Mar 27, 2017 at 15:13
  • 1
    @Zimmi48 I've got to say, I kinda disagree with you here. We see tons of questions over "can this be licensed?" and heck, regex is clearly something you'd see in open source. If you see regex in a project, it's a perfectly valid question to ask: "is the regex under GPL, or can it not be copyrighted?" In such a case, the question applies both to Law and Open Source, and because of that, I'm unwilling to migrate as I believe it's on-topic here. If the question eventually gets closed, then I'll send it over :)
    – Zizouz212
    Mar 28, 2017 at 2:25
  • 3
    @Zizou212 would the OP have said "I found it in a GPL program" or "Can I copy it in my open source program" I would indeed consider the question on-topic but there is no relation whatsoever to open source in the current formulation.
    – Zimm i48
    Mar 28, 2017 at 6:34
  • I don't really understand what this website is for, but it seems related: regexlicensing.org May 27, 2021 at 2:50

2 Answers 2


The >>idea<< of the regex can't be copyrighted (though it could conceivably be patented, but that's real unlikely to be the case), only its particular >>expression<< (its particular syntax). And there's usually more than one way to construct a regex that does the same thing. So if you're really concerned, just use the idea and rewrite it a little differently, e.g., to rewrite or not to rewrite, that is the question.

  • I actually find it highly unlikely that there would be multiple correct ways to implement a regex.
    – RubberDuck
    Mar 30, 2017 at 1:06
  • @RubberDuck see, e.g., en.wikipedia.org/wiki/… Apr 1, 2017 at 0:58
  • @RubberDuck Even trivial regexes can be easily written in multiple correct ways. A regex matching the string "A A" could be written /A A/, /(\x41) \1/, /(?:A)\x20[\u0041]/, /()()()()()()A A/, etc etc. Whether such variations would meet "originality" requirements is another matter (not that it'd matter for trivial examples), but the exploding complexity of more substantial examples would also lead to an exploding number of possible variations, even without resorting to less correct or less performant ones. Jan 8, 2022 at 2:17
  • @LionelRowe I feel like you hit on the meat of what I was getting at. These kinds of replacements would likely not meet originality requirements. It would honestly depend on how willing the judge presiding over the case is to learn about regex.
    – RubberDuck
    Jan 10, 2022 at 13:33

There are a number of things to consider:

  1. Have you contacted the original author(s) to ask them if you can re-use it and under what terms? - They may just say yes, ask for attribution, ask for a fee that you would be willing to pay or agree to release it under an Open Source licence that is also compatible with commercial use. Many of us are just happy to see clever things that we came up with re-used.
  2. How hard would it be for you to come up with your own version, not by changing theirs but possibly by testing against theirs given that you know it is possible to do this by a regex. Keep this in mind if you end up negotiating on price/use.
  3. Did the original page &/or site assert any of licence, copyright, confidentiality or patent on the regex, or code, on the site? - If it did not then they cannot patent in most places as they have already published. If they published it without asserting copyright then technically they have released it into the wild with default copyright and licence which I am told is "all rights reserved". It is worth a thorough look at the site that you found the code on as you may find that there is a default licence applied to all content on the site as there is for all code on the Stack Overflow site(s) for example.

N.B. I am not a lawyer or legal expert in any country, let alone wherever you are - the above is my personal opinion based on past experiences and reading.

  • 4
    Copyright exists automatically, and does not have to be asserted explicitly. The default license is “all rights reserved”. Automatic copyright is codified internationally in the Berne convention. Therefore, the conclusion of your third point is very incorrect, please edit it accordingly. Your other points – asking the author for permission or reverse-engineering the program – are good suggestions, though.
    – amon
    Mar 27, 2017 at 8:44
  • @amon - point 3 updated and expanded to include the fact that there may be a default licence on the site content. Mar 27, 2017 at 12:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.