PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>SELECT ?descriptor ?labelFROM <http://id.nlm.nih.gov/mesh>WHERE {?descriptor a meshv:Descriptor .?descriptor rdfs:label ?label .FILTER(REGEX(?label, 'Cobra'))}ORDER BY ?label
from rdflib.namespace import RDFS, Namespacefrom rdflib.plugins.sparql import prepareQueryMESHV = Namespace('http://id.nlm.nih.gov/mesh')prefixen = { 'rdfs': RDFS, 'meshv': MESHV }q = prepareQuery("""SELECT ?descriptor, ?label WHERE {?descriptor a meshv:Descriptor .?descriptor rdfs:label ?label .FILTER(REGEX(?label, ?expr)""", initNs=prefixen)