Pattern contains multiple special characters

Hello

How to write a Yang pattern statement correctly using the following regex:
([a-zA-Z0-9]|(|)|+|,|-|.|:|=|?|’|"|!|@|#|$|%|^|&|*|_|;|<|>|/|\|||}|{|[|]|`|~| ){1,80}
?

Without quotes: won’t work because there is a ; character
Within single-quote: won’t work because regex contains a ’ character
Within double-quote: won’t work because there are escaped characters other than the allowed ones ( \n, \t, ", \ )

Thanks in advance!

Wow, is that actually an expression you want to use, or some kind of stress-test?:slight_smile:

Actually, the character in your regexp is not the ascii single-quote a.k.a. apostrophe that YANG defines for quoting, but Unicode ‘RIGHT SINGLE QUOTATION MARK’ (U+2019), i.e. single-quote should work just fine. But if you really need a single-quote in a string that you would want/need to enclose in single-quotes, you can use the “switch quote and concatenate” trick:

'([a-zA-Z0-9]|(|)|+|,|-|.|:|=|?|' + "'" +
'|"|!|@|#|$|%|^|&|*|_|;|<|>|/|\|||}|{|[|]|`|~| ){1,80}'

Thank you for your comprehensive answer!

Unfortunately, I got the expression from external service so it’s not up to me :slight_smile:

I’ll try trick you mentioned.
If any problems, I’ll get back here.
Meanwhile, thank you