preg_replace examples

$result = preg_replace('/abc/', 'def', $string);   # Replace all 'abc' with 'def'
$result = preg_replace('/abc/i', 'def', $string);  # Replace with case insensitive matching
$result = preg_replace('/\s+/', '', $string);      # Strip all whitespaces

3.89
9
Phoenix Logan 186125 points

                                    $result = preg_replace(
    array('/pattern1/', '/pattern2/'),
    array('replace1', 'replace2'),
    $string
);

3.89 (9 Votes)
0
4.5
2
Phoenix Logan 186125 points

                                    # Strip HTML tag
$result = preg_replace('#<span id="15">.*</span>#m', '', $string);

4.5 (2 Votes)
0
5
2
Lionel Aguero 33605 points

                                    $result = preg_replace('/abc(def)hij/', '/\\1/', $string);
$result = preg_replace('/abc(def)hij/', '/$1/', $string);
$result = preg_replace('/abc(def)hij/', '/${1}/', $string);

5 (2 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
preg_replace python php preg_replace function php preg_replace ., preg replace string with variable preg_replace character preg_replace array of patterns preg replace php & php preg_replace callback preg replace + php php preg_replace replace ' preg_replace('/\D/','' preg_match_all replace preg_replace( preg_replace With Option e preg_replace ( preg_replace callback preg_replace or condition preg_replace() in php is preg_replace a php fuction val().preg_replace() preg_replace php exploit preg_replace exploit php preg_replace script php preg_replace / preg_replace php 8 php str preg_replace preg replace in php preg_replace() PHP Function preg_replace + php preg_replace()? preg_replace php 7.4 preg_replace return php php preg_replace examples pre replace php preg_replace $1 preg_replace in php loop php preg_replace www preg_replace('/\s+/' preg_replace with variable inside pattern php preg_replace with variable php str_replace preg_replace php preg_replace php preg_replace get matched preg_replace get just $1 preg_replace match strng preg_replace_all in php speace preg_replace( preg_replace ( find and replace + preg match php using preg_match with preg_replace preg_replace array of replaces preg_replace_callback example php preg replace in preg replcae use a php function in preg_replace preg_replace global php php preg_replace_callback preg_replace (\d+) $1 how to use preg_replace in php preg_replace example end word preg_match replace php preg_replace \ preg_replace in wordpress preg_replace array preg_replace('#/+#', preg replace \\1 preg_replace apostrophe replace $ inusing preg replace preg_replace generator preg_match_all replace php preg_replace_callback() preg_replace_all php preg replace php example preg_replace function in php preg_replace function preg_replace & php preg_replace php Preg_replace($pattern generator) preg_replace php use function for replace preg_replace php replace function preg replace () php preg replace php preg_replace php 7 preg_replace in python preg replace i preg_replace_callback in php preg_replace_callback php preg_replace in php. preg_replace in php preg_replace('/<!--(.|\s)*?-->/' Warning: preg_replace() preg_replace() use of preg_replace in php preg replace php preg_replace
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source