Skip to content
Advertisement

Tag: regex

REGEXP_SUBSTR to extract a substring from Vertical SQL

I am trying to run the below query to get a substring from a string but it gives wrong result. I am not sure how to use the regex since the regex I am using works well with PCRE. I am expecting to get ndehqb-a3g4-a10 in this case but it prints the original string itself. The ask is to get

SQL, extract everything before 5th comma

For example, my column “tags” have I’m trying to return everything before 5th comma. below is the result example I’ve tried below code but it’s not working. Answer You can use See the regex demo. The REGEXP_REPLACE will find the occurrence of the following pattern: ^ – start of string (([^,]*,){4}[^,]*) – Group 1 (1 refers to this part of

If a string is enclosed in quotes either ” or ‘. I have to remove those starting and ending quotes in snowflake

Check the following input/output examples: Input: “”Nag”ndra”” -> Expected output: “Nag”ndra” Input: ‘N’agendra -> Expected output ‘N’agendra I tried the below query to implement that behavior, which is able to remove the starting and ending quotes. for second example it is given as N’agendra it should be ‘N’agendra Answer If you want to keep the starting ‘ then don’t use

Find value that is not a number or a predefined string

I have to test a column of a sql table for invalid values and for NULL. Valid values are: Any number and the string ‘n.v.’ (with and without the dots and in every possible combination as listed in my sql command) So far, I’ve tried this: The regular expression also matches the single character values ‘n’,’N’,’v’,’V’ (with and without a

Using REGEXP_SUBSTR to extract website domain

I have a field called Website with examples that look like: I am trying to use REGEXP_SUBSTR to isolate the domain: REGEXP_SUBSTR(“Website”, ‘[^https://]+’) Some of the results are working but others are not, for instance I am expecting cornstalk.com and penny.co but I am not receiving those values: Any help would be appreciated. Answer You can use Details: ^ –

Hive regexp_extract numeric value from a string

I have a table as: I am trying to get the numeric values from the table. The expected output is A -> 123 / B -> 124 etc I am trying to do using regexp_extract Any suggestions please? Answer If the delimiters are fixed – ‘; ‘ between key-value pairs and ‘=’ between key and value, you can use str_to_map

Remove duplicate values from comma separated variable in Oracle

I have a variable (called: all_email_list) which contains 3 email address lists altogether. (I found some similar question but not the same with a proper solution) Example: test@asd.com, test2@asd.com,test@asd.com,test3@asd.com, test4@asd.com,test2@asd.com (it can contain spaces between comas but not all the time) The desired output: test@asd.com, test2@asd.com,test3@asd.com,test4@asd.com Any solution to solve this in a simple way? By regex maybe. Answer Solution

How to get text among in blanket [] (Presto)

How to get the result ‘xxx’ from blanket [ ] in presto. I can’t find the proper regexp to fix my problem Could you help me out? Thank you Answer If you have strings like this: and want to extract substring between square brackets, use this:

Advertisement