我想删除以WITH data_table AS (
SELECT 'A' user_code, 'Root ID' description, 'B' parent_code FROM dual
UNION
SELECT 'B' user_code, 'Level1' description, 'C' parent_code FROM dual
UNION
SELECT 'C' user_code, 'Level2' description, 'D' parent_code FROM dual
UNION
SELECT 'D' user_code, 'Level3' description, 'E' parent_code FROM dual
UNION
SELECT 'E' user_code, 'Level4' description, 'F' parent_code FROM dual
)
SELECT MAX(SYS_CONNECT_BY_PATH(user_code,'->'))
FROM data_table
CONNECT BY prior parent_code = user_code
START WITH user_code = 'A'
和space
符号开头的文字末尾的所有字词。
不应删除句子中的URLS或主题标签。
示例文字:
#
我尝试了这个但它删除了所有的标签:
hello world #dontremoveme foobar http://example.com/#dontremoveme #remove #removeme #removeüäüö
我的想法是检查文本末尾的每个单词,检查前面有$tweet = "hello world #dontremoveme foobar http://example.com/#dontremoveme #remove #removeme #removeüäüö";
preg_match_all("/(#\w+)/", $tweet, $matches);
var_dump( $matches );
的前导#
,直到不再是这种情况。
如何将其翻译成正则表达式?
答案 0 :(得分:0)
您可以使用类似的内容:( #[^# ]+?)+$
并将其替换为空字符串。
有一个例子here。由于您有非ASCII字符,.
运算符(与任何字符匹配)应该可以帮助您处理任何字符。
答案 1 :(得分:0)
答案 2 :(得分:0)
这将完成这项工作:
$tweet = "hello world #dontremoveme foobar http://example.com/#dontremoveme #remove #removeme #removeüäüö";
$res = preg_replace("/ #\p{L}+\b(?!\s+\p{L})/u", '', $tweet);
echo $res,"\n";
<强>输出:强>
hello world #dontremoveme foobar http://example.com/#dontremoveme