'Azure Databricks RegEx: PatternSyntaxException

I have a RegEx expression that has been running without fail for many months. As of today it no longer works. This command is running as part of a SQL magic cell in a Databricks notebook on Azure.

CAST
 WHEN NOT (phone REGEXP "^\\(?[2-9][0-8][0-9]\\)? ?[2-9][0-9]{2}-?[0-9]{4}\\b") THEN"S"
 ELSE "" 
END AS exception

The error I get is:

PatternSyntaxException: Unknown inline modifier near index 3
^(?[2-9][0-8][0-9])? ?[2-9][0-9]{2}-?[0-9]{4}

Does anyone know the cause of this issue or how to resolve it?

Many Thanks



Solution 1:[1]

PatternSyntaxException: Unknown inline modifier near index 3 ^(?[2-9][0-8][0-9])? ?[2-9][0-9]{2}-?[0-9]{4}

  • This exception is thrown from Pattern's compile() and matches() methods.

  • The constructor stores the specified description, regex, and index where the syntax error occurs in the regex. The index is set to -1 when the syntax error location isn't known.

  • check your String is syntactically valid regular expression:

boolean isRegex;
try {
  Pattern.compile(your regex string);
  isRegex = true;
} catch (PatternSyntaxException e) {
  isRegex = false;
}

References:
Regular expressions in Java, Part 2: The Regex API
How to check if a string is a valid regex in Python?

Solution 2:[2]

What do you mean upload ".txt"? I googled it and first few seconds into the research I found this: [![enter image description here][1]][1] [![enter image description here][2]][2]

It's a image/video hosting service not a cloud storage service. But there are tons of such services that allow uploading [1]: https://i.stack.imgur.com/b09yV.png [2]: https://i.stack.imgur.com/aGbyO.png

Solution 3:[3]

You didn't specify what error you're receiving, but Cloudinary does support non-image, non-video uploads, which are called 'raw' files: https://cloudinary.com/documentation/upload_images#uploading_non_media_files_as_raw_files

A possible error you may encounter is if you haven't set the resource_type to raw in your API call, or if you've set resource_type to auto but the filename of the uploaded file wasn't sent on the upload API call. In that case, it's likely that Cloudinary was expecting an image file, and didn't detect that you sent a .txt file.

If so, you'll receive an 'invalid image file' error if the file was treated as an image - specifying the resource type explicitly should resolve that

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SuryasriKamini-MT
Solution 2 Shiven Dhir
Solution 3 Igy