2

I was thrilled to see that dbplyr supports the str_detect() command. However, it doesn't work properly with regular expressions when I do a query on a SQL Server database via a ODBC connection: the special character "." is, for instance, not interpreted as a wildcard, but as the character that it is, so a period. Are there any workarounds?

For example,

my_tbl%>%filter(str_detect(COL1, "A123.4"))

will match "A123.4", but not "A123x4".

3
  • I think you might have a typo in your code. Your regex string is "A123.4" so it wont match "A123x5" because it ends in a 5. It will, however, match "A123x4" and "A123.4". If you need it to also match 5, you could try: str_detect(COL1, "A123.[4-5]") Commented Jul 28, 2018 at 4:52
  • You are right, I had a typo in my post. Thank you for pointing that out. I just corrected it. But the problem remains the same. Commented Jul 28, 2018 at 8:46
  • No problem, I was just double checking. Commented Jul 28, 2018 at 13:10

1 Answer 1

1

Sql server does not support regular expressions. The only ways to do so would be to write a custom CLR assembly for a proc/function, or do what you can with wildcards before applying a regex in your application code.

Fwiw you can achieve your goal with 'A123_4' where the underscore is the closest equivalent to "." In regex

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.