用sparql中的正则表达式拆分逗号分隔的字符串

gio*_*gix 3 regex sparql

我必须在 SPARQL 中提出一个关于 regex() 的问题。我想替换一个变量,该变量有时包含一个带逗号的短语,另一个变量只包含逗号之前的内容。例如,如果变量包含“我喜欢它,好的”,我想获得一个包含“我喜欢它”的新变量。我不知道使用哪些正则表达式。

Jos*_*lor 6

This is a use case for strbefore, you don't need regex at all. As a general tip, I suggest reading (or skimming) through the table of contents for Section 17 of the SPARQL 1.1 Query Language Recommendation. It lists all the SPARQL functions, and while you don't need to memorize them all, you'll at least have an idea of what's out there. (This is good advice for all programmers and languages: skim the table of contents and the index.) This query1 shows how to use strbefore:

select ?x ?prefix where { 
  values ?x { "we invited the strippers, jfk and stalin" }
  bind( strbefore( ?x, "," ) as ?prefix )
}
Run Code Online (Sandbox Code Playgroud)
---------------------------------------------------------------------------
| x                                          | prefix                     |
===========================================================================
| "we invited the strippers, jfk and stalin" | "we invited the strippers" |
---------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

1. See Strippers, JFK, and Stalin Illustrate Why You Should Use the Serial Comma