0

Oracle Database 11g: when I run

select REGEXP_COUNT(' ŁÜ||AB!#$%&''()*+,- .:;<=>?@[\]^_&#96;{}/~ ', '[ 0-9A-Za-z!#$%&''\(\)\*\+,\.:;<=>\?@\[\^_&#96;\{\}\/~\-]') "HOW MANY" from dual;

I have result 34.

I want just add '\]' to the pattern and I expect value 35, but Oracle returns 1.
select REGEXP_COUNT(' ŁÜ||AB!#$%&''()*+,- .:;<=>?@[\]^_&#96;{}/~ ', '[ 0-9A-Za-z!#$%&''\(\)\*\+,\.:;<=>\?@\[\^_&#96;\{\}\/~\-\]]') "HOW MANY" from dual;

What should I do to get 35?

szaroblekitny
  • 130
  • 1
  • 5
  • 1
    You are overescaping it all. But the main issue is that you need to use `]` right after the open `[`. [Here](https://stackoverflow.com/a/19420806/3832970) is the answer. – Wiktor Stribiżew Mar 17 '20 at 11:02
  • It doesn't work for me. Can you quote the literal select which will give the value 35 for the given string? Of course there is ` not ``` – szaroblekitny Mar 17 '20 at 11:10
  • https://rextester.com/ZGMNM3393 – Wiktor Stribiżew Mar 17 '20 at 11:17
  • Yes, as per the linked answer. – Wiktor Stribiżew Mar 17 '20 at 12:15
  • Ideally, you shouldn't just get a query that gets you the desired result. There is a lot to learn from this experience. Within character classes, there is no "escape" concept. There are very few special characters to begin with, and if you need them to have their verbatim meaning, you must **place** them where their special meaning doesn't make sense. The example you needed - the right bracket in the first position (or right after the caret in a *negated* character class) has no meaning as a meta-character; in that position, it stands for itself, and that's the only way to include it. –  Mar 18 '20 at 02:38

0 Answers0