Solved

Remove links from file, special characters and integers.

Posted on 2010-08-28
2
358 Views
Last Modified: 2013-12-26
Hi,

I'm having a tough time figuring out the easiest way to remove all special characters, URLs and integers from a central file. Any help would be greatly appreciated
0
Comment
Question by:faithless1
2 Comments
 
LVL 26

Accepted Solution

by:
wilcoxon earned 500 total points
ID: 33551591
Something like this should work...
#!/usr/local/bin/perl
use strict;
use warnings;
use Tie::File;
use Regexp::Common;

my @file;
tie @file, 'Tie::File', 'central_file' or die "could not tie file: $!";
foreach my $line (@file) {
    # remove integers
    $line =~ s{\b$RE{num}{int}\b}{}g;
    # remove URLs
    # $line =~ s{\b$RE{URL}\b}{}g; # doesn't actually exist yet
    $line =~ s{\b(?:https?|ftp|gopher|file):// # protocol
               (?:[\w\d%.+]+/?)* # dir/file
              \b}{}gx;
    # remove special characters - choose one of these methods
    $line =~ s{[^\w\d\s\-]}{}g; # any characters you want to keep
    $line =~ s{(?:\x1B|\x1C)}{}g; # any characters you want to get rid of
}
untie @file;

Open in new window

0
 

Author Comment

by:faithless1
ID: 33607244
Sorry for the late response. Thanks for the code!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

785 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