Skip to content

Instantly share code, notes, and snippets.

@ifirmawan
Created July 18, 2018 13:01
Show Gist options
  • Save ifirmawan/6aa1435aee68f604b40558d6dc8ef017 to your computer and use it in GitHub Desktop.
Save ifirmawan/6aa1435aee68f604b40558d6dc8ef017 to your computer and use it in GitHub Desktop.
Regex to delete all words containing numbers from a sentence
<?php
$str = 'This is S3F8G m7j34m h98H40D-3D39 90843-432423 LSDF3 4X4it very good 343c3.';;
preg_match_all("/(^[\D]+\s|\s[\D]+\s|\s[\D]+$|^[\D]+$)+/",$str,$result);
$result = implode('',$result[0]);
echo $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment