I'm trying to matching everything in comma delimited string that is not a Change Notice (CN) id, which is an alpha-numeric id starting with "CN". The string is a list of items separated by a comma, where each item entry shows the item id followed by a "~-~" and some jargon.
He's an example string:
CN98765432~-~ECN for A01234 Rev A,CR00098765~-~ECR for A12345 SOME PART NAME,CN12345678~-~ECN for A12345 Rev A
In this string, I want to match everything except "CN98765432" (which appears at the beginning) and "CN12345678" (which appears at the end after the last comma)
I've tried using .*(?=CN\d)
, which I assumed would grab everything that ends before a "CN", but that incorrectly matched
CN98765432~-~ECN for A01234 Rev A,CR00098765~-~ECR for A12345 SOME PART NAME,
, which includes the initial CN.
I also tried .*((?=CN\d)|$)
, but that matched the entire string.
I've looked at similar problems but I was not able to adapt the answers into something suitable for my issue.
How to match "anything up until this sequence of characters" in a regular expression?
How do I match everything except for the CN IDs?
I'm using regex ex inside a java based software, so I believe this is a JavaScript flavored regex.