DBT Validation for Date with (yyyy-mm-dd) format - dbt

I would like to ask for your assistance because I'm currently having difficulties to implement date validation with this format (yyyy-mm-dd) I tried to use this command below, unfortunately I'm getting an error. Your response is highly appreciated. Thank you so much.
- dbt_expectations.expect_column_values_to_match_regex:
regex: "^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$"

Your regex is in the style of a raw string (you aren't doubling your backslashes). You need to add an argument to the test definition to tell dbt_expectations to parse it as a raw string:
- dbt_expectations.expect_column_values_to_match_regex:
regex: "^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$"
is_raw: True
Alternatively, you could double all the backslashes:
- dbt_expectations.expect_column_values_to_match_regex:
regex: "^\\d{4}\\-(0[1-9]|1[012])\\-(0[1-9]|[12][0-9]|3[01])$"
Docs are here.

Related

SQL REGEXP_CONTAINS with dot - Google BigQuery

Working on Google BigQuery, kinda newbie.
I'm trying to capture if in a field there a string like "LS" or "L.S".
So far i've written this piece of code:
IF (REGEXP_CONTAINS(subfamilia_ds, "LS") = true OR REGEXP_CONTAINS(subfamilia_ds, "L.S") = true,true,false) = true THEN "LS"
However, for some reason that goes beyond my SQL knowledge, it's returning values such as "OUTROS MOLUSCOS BALCAO" that as neither "LS" nor "L.S".
I'm really struggling with this, and maybe it's a "dumb" issue.
Thank you in advance for the help!
The regex pattern you want to match LS or L.S is either L\.?S or L[.]?S. The middle dot is optional, and also it is a regex metacharacter which has a special meaning of any single character, and hence it must be escaped to mean a literal dot. Try this updated version:
IF (REGEXP_CONTAINS(subfamilia_ds, "L\\.?S") = true) THEN "LS"

Extract characters between a string and the first occurrence of something in BigQuery

I want to extract a set of characters between "u1=" and the first semi-colon using a regex. For instance, given the following string: id=1w54;name=nick;u1=blue;u2=male;u3=ohio;u5=
The desired regex output should be just blue.
I tested (?<=u1=)[^;]* on https://regex101.com and it works. However, when I run this in BigQuery, using regexp_extract(string, '(?<=u1=)[^;]*') , I get an error that reads "Cannot parse regular expression: invalid perl operator: (?<"
I'm confused why this isn't working in BQ. Any help would be appreciated.
You can use regexp_extract() like this:
regexp_extract(string, 'u1=([^;]+)')

BigQuery - Illegal Escape Sequence

I'm having an issue matching regular expression in BigQuery. I have the following line of code that tries to identify user agents:
when regexp_contains((cs_user_agent), '^AppleCoreMedia\/1\.(.*)iPod') then "iOS App - iPod"
However, BigQuery doesn't seem to like escape sequences for some reason and I get this error that I can't figure out:
Syntax error: Illegal escape sequence: \/ at [4:63]
This code works fine in a regex validator I use, but BigQuery is unhappy with it and I can't figure out why. Thanks in advance for the help
Use regexp_contains((cs_user_agent), r'^AppleCoreMedia\/1\.(.*)iPod')

Regular expression for date in selenium ide

I tried to create a regular expression for the below date format, where as I am unable to justify that, please help me out.
04-Apr-2013 [10:58:13 GMT+05:30]
This is what I came up with:
\\d{2}-\\w{3}-d{4} [\\d{2}:d{2}:d{2} \\w{3}+\\d{2}:d{2}]
Correct me where i have gone wrong.
Thanks
You have to escape the square brackets as they have a special meaning in regular expressions and also some of your digit indicators doesn't have backslash prefix. I've tested the following regex and it worked for me:
regexp:\d{2}-\w{3}-\d{4} \[\d{2}:\d{2}:\d{2} \w{3}\+\d{2}:\d{2}\]

What is the Escape character for SQL snippet file

I am writing a SQL Snippet in VS2010 and I want to have "$" as a character inside the SQL Snippet, but the way the snippet recognize a variable is by bounding a word with "$". EX: $var1$
Anybody know what the escape character is for SQL Snippet in VS2010, so it won't think of it as a variable by mistake?
Thank You.
You should be able to escape it by doubling it - try $$.
Use $$ (from here: http://conceptdev.blogspot.com/2006/08/visual-studio-2005-snippets-literal.html).