Solved

Combine Two String Replace RegEx into One

Posted on 2006-11-23
3
211 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
3 Comments
 
LVL 2

Accepted Solution

by:
jingks03 earned 125 total points
Comment Utility
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
Comment Utility
Great. That seems to work. Thanks.
0
 
LVL 84

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now