strpping words - perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting strpping words - perl script
# 1  
Old 02-07-2009
strpping words - perl script

hi below is a regex that i have framed to strip some bad words from my text.

(\bDAMN\s?|FART|FUCK(ED|ER|ING|ME|S)\b)|(\b(HELL|HORNY|J(AC|ER)K-OFF|JI(SM|Z(M)?))\b)|(\b(MOTHA|MOTHER)?FUCK(ER(S)?|IN(G)?)?\b)|(\b(SHIT(TY|S)?|SLUT(S)?|SPUNK|TWAT)\ b)|(ASS(ES)?\s?HOLE(S)?\s?)|(\bBITCH(ES|IN|ING)?+\s?HOLE(S))|(\bBLOW\s?(JOB|JOBS))|(\bCOCK\s?(S|SUCK |SUCKER|SUCKING|SUCKS)\b)|(\bSUCK(S)\b)|(^NAME$|^SELF$|^NONE$|^NA$|^PERSONAL$|^HOME$|^STUDENT$|^RESI DENCE$|^INDIVIDUAL$|^N/A$|^UNKNOWN$)|(\bNAME\b)|(\bSELF\b)|(\bNONE\b)|(\bNA\b)|(\bN/A\b)|(\bPERSONAL\b)|(\bHOME\b)|(\bSTUDENT\b)|(\bRESIDENCE\b)|(\bINDIVIDUAL\b)|(\b(PHONESEX|PISSOFF|P RICK(S)?|PUSS(IES|Y)(S)?)\b)|(\b(CUM(S)?|CUNT(S)?)\b)


i need to implement this in a perl script. if i use the regex in perl script as below i get an illegal variable error.

perl -pe "sSmilie\bDAMN\s?|FART|FUCK(ED|ER|ING|ME|S)\b)|(\b(HELL|HORNY|J(AC|ER)K-OFF|JI(SM|Z(M)?))\b)|(\b(MOTHA|MOTHER)?FUCK(ER(S)?|IN(G)?)?\b)|(\b(SHIT(TY|S)?|SLUT(S)?|SPUNK|TWAT)\ b)|(ASS(ES)?\s?HOLE(S)?\s?)|(\bBITCH(ES|IN|ING)?+\s?HOLE(S))|(\bBLOW\s?(JOB|JOBS))|(\bCOCK\s?(S|SUCK |SUCKER|SUCKING|SUCKS)\b)|(\bSUCK(S)\b)|(^NAME$|^SELF$|^NONE$|^NA$|^PERSONAL$|^HOME$|^STUDENT$|^RESI DENCE$|^INDIVIDUAL$|^N/A$|^UNKNOWN$)|(\bNAME\b)|(\bSELF\b)|(\bNONE\b)|(\bNA\b)|(\bN/A\b)|(\bPERSONAL\b)|(\bHOME\b)|(\bSTUDENT\b)|(\bRESIDENCE\b)|(\bINDIVIDUAL\b)|(\b(PHONESEX|PISSOFF|P RICK(S)?|PUSS(IES|Y)(S)?)\b)|(\b(CUM(S)?|CUNT(S)?)\b):-:g" input.txt >> output.txt

is this because of the words that i use between ^ and $ and is it advisable to use possesive qualifier + in the script.
# 2  
Old 02-07-2009
That is quite a load to look at, I suggest taking it one section at a time add in a new section when the old passes.

For instance start with:

(\bDAMN\s?|FART|FUCK(ED|ER|ING|ME|S)\b)

If that passes add on:

(\bDAMN\s?|FART|FUCK(ED|ER|ING|ME|S)\b)|(\b(HELL|HORNY|J(AC|ER)K-OFF|JI(SM|Z(M)?))\b)

etc...
# 3  
Old 02-07-2009
I tried your regexp on a simple string and hte only problem was here:

(\bBITCH(ES|IN|ING)?+

You can't have ?+ together like that (nested quantifiers). Remove the + and retry your code. Not sure how long your post will be allowed to remain with all those vulgar words in it though.
# 4  
Old 02-07-2009
Personally I might go with a more maintainable approach than that long winded regexp to filter out words from a file but if its a one shot deal it should be OK.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: Pattern to remove words with less than 2 characters.

Hello. I've been thinking about how to go about this. I know I'm close but still does not work. I need to remove any word in that is not at least 2 characters long. I've removed all the non-alphabetic characters already (numbers included). Here's an example: my $string = "This string is a... (4 Replies)
Discussion started by: D2K
4 Replies

2. Shell Programming and Scripting

Perl to remove words between patterns

Hi, I am using following code to remove words between start and end points. $mystring = "The start text always precedes the end of the end text."; if($mystring =~ s/start(.*)end/\0/) { print $1; print "\n"; print $mystring; } But this is writing special chars in place of... (1 Reply)
Discussion started by: sarbjit
1 Replies

3. Shell Programming and Scripting

counting words with perl?

how to use perl to count number of lines, words characters in a file. (3 Replies)
Discussion started by: winter9
3 Replies

4. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

5. Shell Programming and Scripting

Perl Script to find & copy words from Web.

I need to write a perl script to search for a specific set of numbers that occur after a series of words but before another. Specifically, I need to locate the phrase today at the summit, then immediately prior to the words tonnes/day copy the number that will be between 100 and 9,999, for example,... (1 Reply)
Discussion started by: libertyforall
1 Replies

6. Shell Programming and Scripting

Perl searching special words in lines

Hi , i am a new with perl, i want to made a script that find in file rows that start with specil words, as an example a line will start with" ............................................. specialword aaa=2 bbb=5 ............................................. and to put this in a new file... (3 Replies)
Discussion started by: alinalin
3 Replies

7. Shell Programming and Scripting

Need to grep 2 words from Perl Script results in Terminal....

Hey guys. I have a .pl script that scans my hosts to see if they are down or up. I can run it anytime I want. The script uses a conf file that contains text lines of the IP addresses of the servers. I run the script from the command line of my terminal (MAC OS) I run: sudo ./scanner.pl brings... (3 Replies)
Discussion started by: yoyoyo777
3 Replies

8. Shell Programming and Scripting

perl: count columns/words in a string

Hi there, I just wanted to know whether there was an easy way of checking the number of white space separated columns or words in a provided string (scalar) without turning it into an array for example if I have a string like this $string="a b c d 6"; obviously if i was using an array i... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

9. Shell Programming and Scripting

extract words from txt using perl

Hi, i will deal with txt file and i want to use perl to extract number of words from this txt ex :if the txt file is a story which contains person names and iwant to extract these names and there is something else that these names which i want perl to extract must match the words (person names) ... (2 Replies)
Discussion started by: eng_shimaa
2 Replies

10. Shell Programming and Scripting

Matching words in Perl

Hi, I have an array in which one column can contain any statement. From multiple rows of that column I want to match the statement like "Execution Started." If that row contains "Execution started." then only I have to fetch other data of other columns of that particular row. I dont want... (2 Replies)
Discussion started by: monika
2 Replies
Login or Register to Ask a Question