If I have a string that begins foo and is 8 characters in length so looks like foo????? What pattern will I need to replace it using preg_replace()?
            Asked
            
        
        
            Active
            
        
            Viewed 577 times
        
    0
            
            
        - 
                    What do you want to replace it with? – sshashank124 Apr 10 '14 at 12:49
- 
                    `''` nothing empty string sorry should have said – andrew Apr 10 '14 at 12:49
- 
                    possible duplicate of [Reference - What does this regex mean?](http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) >> jump to quantifiers and "any character" – HamZa Apr 10 '14 at 12:52
3 Answers
1
            
            
        You can easily do that by matching:
/(foo)(.{5})/
and replacing with
''
 
    
    
        sshashank124
        
- 31,495
- 9
- 67
- 76
1
            
            
        preg_replace('^/foo.{5}$/','',$string)
This should fit your needs.
Search in $string for
^  //Begin of the line
foo //Text your searching for
. //Some character
{5} //5 times the dot as character.
$ // end of line
and replace it with '' (second parameter)
 
    
    
        Xatenev
        
- 6,383
- 3
- 18
- 42
 
     
    