[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

Combine Two String Replace RegEx into One

I have two string replace ReEx's, like:

$string =~s/\n<\/STRIKE>/<\/STRIKE>\n/g;
and
$string =~s/\n<\/U>/<\/U>\n/g;

I figure it would be more efficient to do these two replace operations in one ReEx. How can I combine them?  I tried ( | ), but that gave a 500 error.
0
Randall-B
Asked:
Randall-B
1 Solution
 
jingks03Commented:
I believe:
$string =~ s/\n<\/(STRIKE|U)>/<\/$1>\n/g;

will work.  The options (STRIKE, U) or in the brackets separated by a pipe '|' which ORs them.  The brackets also strore whichever options it is in $1.
0
 
Randall-BAuthor Commented:
Great. That seems to work. Thanks.
0
 
ozoCommented:
You could also do it like
$string =~ s#\n(</(STRIKE|U)>)#$1\n#g;
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now