query-77b026a1b096609cc591e88c2b93679b

rq turtle/ttl

13:41, 4 February 2022 (UTC) dosisEpìyou can see that my regex contains two subgroups, ([\S\s]+\d+[\S\s]) and ([\S\s]). Is there a way to assign two variables to these two subgroups, so that I can display them as columns in the results of the query? Thanks, --I have found (unexpectedly) an inelegant but somehow efficient solution:

Use at

PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
SELECT ?item ?id ?name ?first ?second
WHERE {
  ?item p:P396 ?st .
  ?st ps:P396 ?id .
  ?st pq:P1810 ?name . FILTER(REGEX(?name, "<(.+\\d+.*)-(.*)"))
  BIND(REPLACE(STR(?name),".+<","") AS ?first_cl)
  BIND(REPLACE(STR(?first_cl),"-.+>","") AS ?first)
  BIND(REPLACE(STR(?name),".+<.+-","") AS ?second_cl)
  BIND(REPLACE(STR(?second_cl),">","") AS ?second)
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?first"):::projected v5("?first_cl") v4("?id"):::projected v2("?item"):::projected v1("?name"):::projected v8("?second"):::projected v7("?second_cl") v3("?st") f0[["regex(?name,'<(.+\d+.*)-(.*)')"]] f0 --> v1 v2 --"p:P396"--> v3 v3 --"p:statement/P396"--> v4 v3 --"p:qualifier/P1810"--> v1 bind1[/"replace(str(?name),'.+<','')"/] v1 --o bind1 bind1 --as--o v5 bind2[/"replace(str(?first_cl),'-.+>','')"/] v5 --o bind2 bind2 --as--o v6 bind3[/"replace(str(?name),'.+<.+-','')"/] v1 --o bind3 bind3 --as--o v7 bind4[/"replace(str(?second_cl),'>','')"/] v7 --o bind4 bind4 --as--o v8