简体   繁体   中英

Multiple Patterns in Regex

Can there be multiple patterns in Regexp_Replace.

Pattern 1 : '^#.*'

Pattern 2: '^//.*'

Pattern 3 : '^&&.*'

I want all three patterns in same regexp_replace function like

select REGEXP_REPLACE ('Unit testing last level','Pattern 1,Pattern 2,Pattern 3','',1,0,'m') 
  from dual;

You can use an alternation group where all alternative branches are | -separated.

^(#|//|&&).*

The (...) form a grouping construct where you may place your various # , && , and other possible "branches". A | is an alternation operator.

The pattern will match:

  • ^ - start of a line (as you are passing m match_parameter)
  • (#|//|&&) - either # , // or &&
  • .* - any 0+ chars other than a newline (since n match_parameter is not used).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM