我有一个字符串,我想捕获“\Close_Out”之前的所有内容:
字符串:\fileshare\R 和 G\123456\Close_Out\Warranty Letter.pdf
我提出的唯一解决方案使用正向前瞻,当我在 https://regex101.com/ 上测试它时,这有效
(.*)(?=\\Close_Out)
但现在我需要在 Oracle SQL 语句中使用它:
select REGEXP_SUBSTR('\\fileshare\R and G\123456\Close_Out\Warranty Letter.pdf', '(.*)(?=\\Close_Out)') from dual
它不起作用,因为(我认为)不支持前瞻。有人可以帮忙提供一个可以在 sql 中使用的替代表达式
最佳答案
如果正则表达式不是必须,则 substr
+ instr
可以完成这项工作:
SQL> with test (col) as
2 (select '\fileshare\R and G\123456\Close_Out\Warranty Letter.pdf' from dual)
3 select substr(col, 1, instr(col,'\Close_Out') - 1) result
4 from test;
RESULT
-------------------------
\fileshare\R and G\123456
SQL>
关于Oracle SQL 中的正则表达式,正向展望,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60513436/