Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the first thing you want is to find a good reference on regex and brush up on things like which chars need to be escaped inside and outside of character class (the square brackets: []). Then clean up your regex by removing {1}'s and using case-insensitive match ('//i') when it makes sense. Then I'm including some code that you can use to consolidate some of your capitalization rules, I hope it helps you.</p> <pre><code>// capitalize first word of each sentence function tidy_sentences($str){ $tokens = array(); foreach(preg_split('/([.?!]\s*)/', $str, 0, PREG_SPLIT_DELIM_CAPTURE) as $token){ if(!preg_match('/([.?!]\s*)/', $token, $m)) $token[0] = strtoupper($token[0]); $tokens[] = $token; } return implode($tokens); } // apply capitalization rules to individual words function tidy_words($str){ $tokens = array(); foreach(preg_split('/([^\w-])/', $str, 0, PREG_SPLIT_DELIM_CAPTURE) as $token){ switch(true){ // tokens you want to uppercase go here case preg_match('/^(uk|kw)$/i', $token, $m): $tokens[] = strtoupper($m[0]); break; // tokens you want to lowercase go here case preg_match('/^(rpm|fl|oz)$/i', $token, $m): $tokens[] = strtolower($m[0]); break; // tokens you want to capitalize first letter go here case preg_match('/^(maxi-sense|side-by-side|d-radius)$/i', $token, $m): $tokens[] = ucfirst($m[0]); break; default: $tokens[] = $token; } } return implode($tokens); } function tidy($str){ return tidy_sentences(tidy_words($str)); } echo tidy('foo bar rpm maxi-sense uk Fl OZ baz! pull out'); // =&gt; Foo bar rpm Maxi-sense UK fl oz baz! Pull out </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload