Skip to content

Instantly share code, notes, and snippets.

@tibotiber
Created August 20, 2014 05:04
Show Gist options
  • Save tibotiber/9b91307c9d61d637f0db to your computer and use it in GitHub Desktop.
Save tibotiber/9b91307c9d61d637f0db to your computer and use it in GitHub Desktop.
Useful N3 regex
qname:          /^([^:\/"']*):([^:\/"']+)$/

exec(...)[0]:   ns:example
exec(...)[1]:   ns
exec(...)[2]:   example
uri:            /^(.*)#(.*)$/

exec(...)[0]:   http://www.example.org/n3/namespace#john
exec(...)[1]:   http://www.example.org/n3/namespace
exec(...)[2]:   john
literal:   /^("([^(\^\^)]*)")(?:\^\^([^\<]*))?$/

exec(...)[0]:   "true"^^xsd:boolean 
exec(...)[1]:   "true"
exec(...)[2]:   true
exec(...)[3]:   xsd:boolean
stringTriple:   /^((('|")([^"']*)('|")([^"'\s]*))|([^'"\s]*))\s([^'"]*)\s((('|")([^"']*)('|")([^"'\s]*[^.]))|([^'"\s]*[^\.]))(\.)?$/

exec(...)[0]:   ns:john ns:says "whatever, it's an example"^^xsd:string.
exec(...)[1]:   ns:john                                    > subject
exec(...)[2]:   undefined                                  > subject if it is a literal
exec(...)[3]:   undefined                                  > literal starting quotes (single or double)
exec(...)[4]:   undefined                                  > literal content
exec(...)[5]:   undefined                                  > literal ending quotes (single or double)
exec(...)[6]:   undefined                                  > literal type
exec(...)[7]:   ns:john                                    > subject if it is not a literal
exec(...)[8]:   ns:says                                    > predicate
exec(...)[9]:   "whatever, it's an example"^^xsd:string    > object
exec(...)[10]:  "whatever, it's an example"^^xsd:string    > object if it is a literal
exec(...)[11]:  "                                          > literal starting quotes (single or double)
exec(...)[12]:  whatever, it's an example                  > literal content
exec(...)[13]:  "                                          > literal ending quotes (single or double)
exec(...)[14]:  ^^xsd:string                               > literal type
exec(...)[15]:  undefined                                  > object if it is not a literal
exec(...)[16]:  .                                          > final dot if any
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment