Regex in perl

Posted on 2014-04-16
Last Modified: 2014-04-18

How do I write a regex in perl that trims each line at "] to the end of that line.

So my result file would look like:


Original file:
0eef2427e-fdde-1341a-b5d1-1bc214721332451.pdf"] was not found or subfolder ["DailyNews"] not created.
0eef2427e-fdde-1341a-b5d1-1b24214721332451.pdf"] was not found or subfolder ["GlobalServicesInc"] not created.
Question by:LuckyLucks
LVL 34

Assisted Solution

by:Dan Craciun
Dan Craciun earned 250 total points
ID: 40005697
Use this:

or, if you really need to stop at the first "], use this:

LVL 26

Accepted Solution

wilcoxon earned 250 total points
ID: 40005777
More efficient (no capture - just removing the unwanted chars) would be this:

Open in new window


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl Script to append xml file 32 191
Filtering a file to table 9 99
Perl passing in variables to do substitution 6 66
File Find regex problem 4 60
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
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…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

929 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

10 Experts available now in Live!

Get 1:1 Help Now