select
regexp_replace(
url,
E'^http:\/\/.*\/(.*)-(\\d+).html(\\?)?(.*)?',
E'\\1'
) as t_name,
regexp_replace(url, E'^.*-(\\d+).html(\\?)?(.*)?', E'\\1') :: integer as t_id,
count(*) as t_cnt
from unnest(
ARRAY [
'http://kody.wig.pl/ustawienie_wartosci_pol_input_w_formularzu_strony-15.html',
'http://kody.wig.pl/ustawienie_wartosci_pol_input_w_formularzu_strony-15.html?
action=test&value1=118-115&value2=119-116'
]
) as t(url)
group by
t_name,
t_id
Wynik:
"ustawienie_wartosci_pol_input_w_formularzu_strony";15;2