2

我有以下情况。

周一上午 8:30 至下午 6:00 <.br> 周二休息 <.br> 周三上午 8:30 至下午 6:00

这里周二不营业。所以我需要从字符串 '<.br>Tuesday Closed' 中排除以下值并生成为:

周一上午 8:30 至下午 6:00 <.br> 周三上午 8:30 至下午 6:00

尝试使用 REGEXP_REPLACE(OfficeHrs,'Closed',' ') 只会发出 Closed 部分,但不确定如何忽略字符串中的<.br>

4

3 回答 3

1

你可以试试这个:

 with tab as(
  select 'Monday 8:30 a.m. to 6:00 p.m. <.br> Tuesday Closed <.br> Wednesday 8:30 a.m. to 6:00 p.m.' as str from dual union all
  select 'Monday 8:30 a.m. to 6:00 p.m. <.br> Tuesday Closed <.br> Wednesday 8:30 a.m. to 6:00 p.m. <.br> Thursday Closed <.br> Sunday 8:30 a.m. to 6:00 p.m.' as str from dual union all
  select 'Monday 8:30 a.m. to 6:00 p.m. <.br> Tuesday Closed <.br> Wednesday Closed <.br> Sunday 8:30 a.m. to 6:00 p.m.' as str from dual
)
select regexp_replace(str,'> [[:alpha:]]* Closed <.br')

from tab;
| REGEXP_REPLACE(STR,'>[[:ALPHA:]]*CLOSED<.BR') |
| :------------------------------------------------ -------------------------------------------------- ---- |
| 周一上午 8:30 至下午 6:00 <.br> 周三上午 8:30 至下午 6:00 |
| 周一上午 8:30 至下午 6:00 <.br> 周三上午 8:30 至下午 6:00 <.br> 周日上午 8:30 至下午 6:00 |
| 周一上午 8:30 至下午 6:00 <.br> 周日上午 8:30 至下午 6:00 |

db<>在这里摆弄

于 2019-07-25T17:26:42.410 回答
1

你最好使用regexp_substr()代替regexp_replace(),和instr()regexp_count()作为辅助功能,并listagg()在最后连接:

with tab as
(
 select 'Monday 8:30 a.m. to 6:00 p.m.
 Tuesday Closed
 Wednesday 8:30 a.m. to 6:00 p.m' as str from dual 
), t1 as
(
select regexp_substr(str,'^.*$',1,level,'m') as str, level as lvl
  from tab
 connect by level <= regexp_count(str,chr(10)) + 1
)
select listagg(str,chr(10)) within group (order by lvl) as "Result String"
  from t1
 where instr(str,'Closed')=0;

Result String
---------------------------------
Monday 8:30 a.m. to 6:00 p.m.
 Wednesday 8:30 a.m. to 6:00 p.m

Demo

于 2019-07-25T17:24:10.620 回答
0

您可以尝试/[^(<.br>)]*Closed\s?<\.br>/匹配,然后将其替换为'' 希望它有帮助

于 2019-07-25T17:26:25.600 回答