perl regular expression to remove the special characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl regular expression to remove the special characters
# 1  
Old 09-03-2012
perl regular expression to remove the special characters

I had a string in perl script as below.

Tue Augáá7 03:54:12 2012

Now I need to replace the special character with space.
After removing the special chaacters

Tue Aug 7 03:54:12 2012

Could anyone please help me here for writing the regular expression?

Thanks in advance..

Regards,
GS
# 2  
Old 09-03-2012
Quote:
Originally Posted by giridhar276
I had a string in perl script as below.

Tue Augáá7 03:54:12 2012

Now I need to replace the special character with space.
After removing the special chaacters

Tue Aug 7 03:54:12 2012

Could anyone please help me here for writing the regular expression?
...
Let's say this value is stored in a variable called "$date".
Then you could try something like this -

Code:
$date =~ s/[^a-z 0-9:]+/ /ig;

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl regular expression

Hi , I have the below array my @actionText = ("delivered to governor on 21/23/3345" , "deliver jllj" , "ram 2345/43"); When i am trying to grep the contents of array and if mathced substituting with the digitis or some date format from the element like below my @action = grep { $_ =~... (7 Replies)
Discussion started by: ragilla
7 Replies

2. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

3. Shell Programming and Scripting

Hidden Characters in Regular Expression Matching Perl - Perl Newbie

I am completely new to perl programming. My father is helping me learn said programming language. However, I am stuck on one of the assignments he has given me, and I can't find very much help with it via google, either because I have a tiny attention span, or because I can be very very dense. ... (4 Replies)
Discussion started by: kittyluva2
4 Replies

4. Shell Programming and Scripting

matched characters - regular expression

Hi, I read the book of <<unix shell programming>>. The regular expression ^\(.\)\1 matches the first character on the line and stores it in register 1. Then the expression matches whatever is stored in the register 1, as specified by the \1. The net effect of this regular expression is to match... (2 Replies)
Discussion started by: jianma
2 Replies

5. Shell Programming and Scripting

Need perl regular expression to remove the comment

I need a perl substitution to remove only the comment in the line . That line may have '#' with in double quotes .I used the following , s/(^.*\".+?#.+?\".+?)(#.*)/$1/g It works for , print " not a comment # not a comment " . "not a comment # not a comment" ; # It is a comment ... (3 Replies)
Discussion started by: karthigayan
3 Replies

6. Linux

how to grep special character regular expression?

Hi :) I have 2 files file1: SNP_A-2208459 SNP_A-4215188 SNP_A-2012248 SNP_A-1882998 file2: CHR SNP UNADJ BONF HOLM * * * etc. 19 SNP_A-2236481 1.742e-26 5.442e-21 13 SNP_A-4204405 8.643e-07 1.505e-06 3 SNP_A-1860908... (11 Replies)
Discussion started by: sogi
11 Replies

7. Shell Programming and Scripting

Regular Expression to match repeated characters

Hello All I have file which contain sample data like below - test.txt ---------------------------------------------- jambesh aaa india trxxx sdasd mentor asss light train bbblah --------------------------------------------- I want to write a regX which would print only those... (4 Replies)
Discussion started by: jambesh
4 Replies

8. Shell Programming and Scripting

searching regular expressions with special characters like dot using grep

hi everybody I am a new user to this forum and its previous posts have been very useful. I'm searching in a file using grep for patterns like 12.13.444 55.44.443 i.e. of form <digit><digit>.<digit><digit>.<digit><digit><digit> Can anybody help me with this. Thanks in advance (4 Replies)
Discussion started by: jpriyank
4 Replies

9. Shell Programming and Scripting

remove special characters from text using PERL

Hi, I am stuck with a problem here. Suppose i have a variable which is assigned some string containing special charatcers. for eg: $a="abcdef^bbwk#kdbcd@"; I have to remove the special characters using Perl. The text is assigned to the variable implicitly. How to do it? (1 Reply)
Discussion started by: agarwal
1 Replies

10. Shell Programming and Scripting

perl regular expression

letz say that my file has 7 records with only one field. So my file has: 11111111 000000000000000 1111 aaaabbbccc 1111111222000000 aaaaaaaa zz All i need is: 1. when the field has a repetition of the same instance(a-z or 0-9), i would consideer it to be invalid.... (1 Reply)
Discussion started by: helengoldman
1 Replies
Login or Register to Ask a Question