Solved

Combine Two String Replace RegEx into One

Posted on 2006-11-23
3
230 Views
Last Modified: 2007-12-19
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
Comment
Question by:Randall-B
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
jingks03 earned 125 total points
ID: 18003814
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
 

Author Comment

by:Randall-B
ID: 18003884
Great. That seems to work. Thanks.
0
 
LVL 84

Expert Comment

by:ozo
ID: 18003885
You could also do it like
$string =~ s#\n(</(STRIKE|U)>)#$1\n#g;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question