I am using ruby on rails with postgresql. I have a table called "teams" with column "team_name". This "team_name" contains values like "1(Team1)", "1(Team2)", "2(Team1)", etc. Now want to take Team1, Team2, Team3 from those team names using sql query. If I use split_part as follows
sql = "SELECT SPLIT_PART(team_name,'(',2) FROM teams where id=20"
result = ActiveRecord::Base.connection.execute(sql).to_a
In the result I am getting
[{"split_part"=>"Team1)"}]
but I want the following result
[{"split_part"=>"Team1"}]
SUSBTRINGwith regex, reference: stackoverflow.com/questions/53636887/…