Solved

Combine Two String Replace RegEx into One

Posted on 2006-11-23
3
214 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTTP Error 502.2 - Bad Gateway 3 217
Perl Awk Need Help 3 119
get the last nth lines from a an array if nth element is xxx 2 71
Perl File::Find alternative 1 70
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.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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