# Pattern contains multiple special characters

**URL:** <https://dmap-community.ductus.global/t/pattern-contains-multiple-special-characters/2644>\
**Category:** YANG\
**Created:** [August 20, 2019, 8:44am UTC](https://dmap-community.ductus.global/t/pattern-contains-multiple-special-characters/2644 "2019-08-20T08:44:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CatchEx](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@CatchEx](https://dmap-community.ductus.global/u/CatchEx)\
**Post date:** [August 20, 2019, 8:44am UTC](https://dmap-community.ductus.global/t/pattern-contains-multiple-special-characters/2644/1 "2019-08-20T08:44:50Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![per](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@per](https://dmap-community.ductus.global/u/per)\
**Post date:** [August 20, 2019, 1:19pm UTC](https://dmap-community.ductus.global/t/pattern-contains-multiple-special-characters/2644/2 "2019-08-20T13:19:53Z")

</div>

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

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

> [@CatchEx](#):
>
> 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, ", \ )

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:

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

---

<div class="post-metadata">

**Author:** ![CatchEx](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@CatchEx](https://dmap-community.ductus.global/u/CatchEx)\
**Post date:** [August 21, 2019, 5:29am UTC](https://dmap-community.ductus.global/t/pattern-contains-multiple-special-characters/2644/3 "2019-08-21T05:29:47Z")

</div>

Thank you for your comprehensive answer!

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

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