Dooley28 Posted April 3, 2008 Share Posted April 3, 2008 Hey all, Was just wondering if anyone had a simple regex to rip all grammar out of a sentence or where I could get one? Thanks! Link to comment https://forums.phpfreaks.com/topic/99447-php-regex-to-rip-out-all-grammar/ Share on other sites More sharing options...
Caesar Posted April 3, 2008 Share Posted April 3, 2008 Bad grammer? Or grammar in general? <?php //Strip out anything that's not a number. $nustr = preg_replace('/[^0-9]/','',$str); ?> Link to comment https://forums.phpfreaks.com/topic/99447-php-regex-to-rip-out-all-grammar/#findComment-508837 Share on other sites More sharing options...
Dooley28 Posted April 3, 2008 Author Share Posted April 3, 2008 Oh any grammar to be honest. So "Here is, some text!! Sir...." would go to an array something like this. array[0]=Here array[1]=is array[2]=some array[3]=text array[4]=Sir That would be great. Cheers Link to comment https://forums.phpfreaks.com/topic/99447-php-regex-to-rip-out-all-grammar/#findComment-508855 Share on other sites More sharing options...
discomatt Posted April 3, 2008 Share Posted April 3, 2008 I believe \p{P} in regex matches punctuation Link to comment https://forums.phpfreaks.com/topic/99447-php-regex-to-rip-out-all-grammar/#findComment-508858 Share on other sites More sharing options...
Caesar Posted April 3, 2008 Share Posted April 3, 2008 Oh...you want to put every word into an array? <?php $str = "This is a sentence that I'm using to test"; preg_match_all('/[aA-zZ\'\.]+/', $str,$words); ?> Above returns.... Array ( [0] => Array ( [0] => This [1] => is [2] => a [3] => sentence [4] => that [5] => I'm [6] => using [7] => to [8] => test ) ) Link to comment https://forums.phpfreaks.com/topic/99447-php-regex-to-rip-out-all-grammar/#findComment-508873 Share on other sites More sharing options...
Dooley28 Posted April 4, 2008 Author Share Posted April 4, 2008 Cool that's perfect. Thank you sir! Link to comment https://forums.phpfreaks.com/topic/99447-php-regex-to-rip-out-all-grammar/#findComment-508896 Share on other sites More sharing options...
writer Posted April 4, 2008 Share Posted April 4, 2008 <?php $str = "This is a sentence that I'm using to test"; preg_match_all('/[aA-zZ\'\.]+/', $str,$words); ?> Thanks for this. Link to comment https://forums.phpfreaks.com/topic/99447-php-regex-to-rip-out-all-grammar/#findComment-508920 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.