0

I'm using Snowflake SQL. How can I remove everything after the last occurence of a character (_) and all digits in the end of a string?

For example:

foo_bar_2
foo_bar_3b
foo3
bar

should become:

foo_bar
foo_bar
foo
bar
  • Looks like you are looking to create a regex, but do not know where to get started. Please check [Reference - What does this regex mean](https://stackoverflow.com/questions/22937618) resource, it has plenty of hints. Also, refer to [Learning Regular Expressions](https://stackoverflow.com/questions/4736) post for some basic regex info. Once you get some expression ready and still have issues with the solution, please edit the question with the latest details and we'll be glad to help you fix the problem. – Wiktor Stribiżew Oct 22 '20 at 14:54
  • Questions that ask ["Give me a regex that does X"](https://meta.stackoverflow.com/q/285733) with no attempt are off topic on Stack Overflow. Also, see [Why is “Can someone help me?” not an actual question?](https://meta.stackoverflow.com/questions/284236) – Wiktor Stribiżew Oct 22 '20 at 15:03
  • @WiktorStribiżew If the main issue is no attempt to solve, then it's _not_ the duplicate you tagged (or that I re-tagged). Instead, just vote to close as too broad, maybe downvote, and move on. You tag _way_ too many questions as duplicate. – Tim Biegeleisen Oct 22 '20 at 15:04
  • But the thing is, it only takes 3 close votes to nail it shut anyway. And questions showing no effort can, and often do, get closed without moderator intervention. Consider only closing as duplicate when that is really the case. – Tim Biegeleisen Oct 22 '20 at 15:06
  • 2
    Unfortunate that this is closed @yanishmathio but here is some sql that may help ```with temp as ( select 'foo_bar_2' as a union all select 'foo_bar_3b' union all select 'foo3' union all select 'bar' ) select left(a,len(a)-charindex('_',reverse(a))) from temp;``` – Daniel Zagales Oct 22 '20 at 15:07

0 Answers0