-1

I've tried to understand the below but don't seem to get the last part of the regular expression which has {1,40}. Overall, I know the pattern tries to match the special characters and something else (the {1,40})

regexp_like(COLUMN,'^['||UNISTR('\0020')||'-'||UNISTR('\0060')||UNISTR('\007B')||UNISTR('\007D')||UNISTR('\007E')||UNISTR('\00C0')||'-'||UNISTR('\00DF')||']'||'{1,40}$')
GMB
  • 188,822
  • 23
  • 52
  • 100
user3055262
  • 365
  • 3
  • 7
  • 19
  • 3
    It's a quantifier. The preceeding token (a character class here) will be repeated 1 to 40 times. – VLAZ Jan 08 '20 at 20:27
  • '||' is putting me off which is right before {1,40}, and so I was not able to confirm my understanding. to me this seemed like an OR condition. So is this still a quantifier for the preceding character class? I am not trying to challenge, but I still have this doubt. – user3055262 Jan 08 '20 at 20:36
  • 1
    The `||` is the SQL string concatenation operator - it's not part of the regexp. – kfinity Jan 08 '20 at 20:40
  • 3
    `||` is string concatenation in Oracle. `"[a-z]"||"{1,40}"` is equivalent to `"[a-b]" + "{1,40}"` in Java or `"[a-b]" . "{1,40}"` in PHP – VLAZ Jan 08 '20 at 20:40
  • amazing. I fully understand it now. Thank you all for the quick resolution – user3055262 Jan 08 '20 at 20:58

1 Answers1

5

regexp_like() checks that a string matches the regex provided as second argument.

Your regexp looks like ^[...]{1,40}$.

  • ^ is the beginning of the string and $ is the end, so the entire string must match the regex.

  • [...] is a character class, that contains a bunch of characters code points. All characters of the string must belong to that list (any other character is forbiden). You would need to to check what they correspond to: unicode.org is your friend. For the first code points:

    \0020    space
    \0060    grave accent
    \007B    left curly bracket
  • finally, {1,40} is a quantifier: the length of the string must be at least one and at most 40.
GMB
  • 188,822
  • 23
  • 52
  • 100