regex

Reply

Join Date: Mar 2008
Posts: 70
Reputation: forzadraco is an unknown quantity at this point 
Solved Threads: 1
forzadraco forzadraco is offline Offline
Junior Poster in Training

regex

 
0
  #1
Feb 12th, 2009
anyone can help me to make regular expression

[code ]

$string="
xxxxx
xxxxx
<body border='0'>
<script language=javascript>
...
word1 ... word2 ... word3... word4
...
</script>

";

i want to remove all word from that string if that string have minimal three word'x'

preg_replace(); how to make that regex?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: regex

 
0
  #2
Feb 12th, 2009
i want to remove all word from that string if that string have minimal three word'x'
I am not clear what you want. Do you want to search for xxx, if found, remove it ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 70
Reputation: forzadraco is an unknown quantity at this point 
Solved Threads: 1
forzadraco forzadraco is offline Offline
Junior Poster in Training

Re: regex

 
0
  #3
Feb 12th, 2009
yes remove all if get same pattern.. the problem is how to make regex pattern...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: regex

 
0
  #4
Feb 12th, 2009
  1. $pattern = "/x{3}/";
  2. $string = preg_replace($pattern,'', $string);
This will look for xxx, if found, replaces it with null.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 70
Reputation: forzadraco is an unknown quantity at this point 
Solved Threads: 1
forzadraco forzadraco is offline Offline
Junior Poster in Training

Re: regex

 
0
  #5
Feb 12th, 2009
not like that.. iwant to remove all from <script> tag till </script> if match with the pattern..

the pattern from
<script .....>
... targetword1..
... targetword2..
... targetword3..

</script>
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 4
Reputation: bastones is an unknown quantity at this point 
Solved Threads: 0
bastones bastones is offline Offline
Newbie Poster

Re: regex

 
0
  #6
Feb 12th, 2009
If you want to see if there are 3 or more x's, use:

  1. $pattern = "/x{3,}/"

The {3} means looking for 3 of the preceding character but {3,} means 3 or more. There's a great tutorial on regex in PHP here: http://www.sitepoint.com/article/reg...pressions-php/
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: regex

 
0
  #7
Feb 12th, 2009
This isn't the best solution (Infact, its kinda sloppy!). First, use preg_match to search for pattern "xxx". If found, then, use preg_match again, but this time, search for pattern, '/<script[^>]+\>(.*)<\/script>/s' . This will again return the string between <script> tags. Then use str_replace and replace the matched string with "".
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC