Combine Two String Replace RegEx into One

I have two string replace ReEx's, like:

$string =~s/\n<\/STRIKE>/<\/STRIKE>\n/g;
$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.
Who is Participating?
jingks03Connect With a Mentor Commented:
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.
Randall-BAuthor Commented:
Great. That seems to work. Thanks.
You could also do it like
$string =~ s#\n(</(STRIKE|U)>)#$1\n#g;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.