# @url http://stackoverflow.com/questions/4519739/split-camelcase-word-into-words-with-php-preg-match-regular-expression
179303
public function splitCamelCase($ccWord){
        $regex =
            '/# Match position between camelCase "words".
            (?<=[a-z])  # Position is after a lowercase,
            (?=[A-Z])   # and before an uppercase letter.
            /x'
        ;
        $result =  preg_split($regex, $ccWord);
        if(is_array($result)){
            return trim(implode(" ",$result));
        }else{
            return $result;
        }
    }
154574
function ucwords(string) {
  if (!(string && typeof string === "string")) {
    return string;
  }
  const words = string.split(" ");

  const formattedWords = _.map(words, (word) => {
    const wordLength = word.length;
    const lowerWord = word.toLowerCase();
    const loweredWordNoPeriod = lowerWord.replace(".", "").replace(",", "");
    const upperCaseWord = word.toUpperCase();

    if (
      word !== upperCaseWord &&
      word !== lowerWord &&
      loweredWordNoPeriod.length > 1
    ) {
      return word;
    }

    if (
      _.includes(
        [
          "AL",
          "AK",
          "AS",
          "AZ",
          "AR",
          "CA",
          "CO",
          "CT",
          "DE",
          "DC",
          "FM",
          "FL",
          "GA",
          "GU",
          "HI",
          "ID",
          "IL",
          "IN",
          "IA",
          "KS",
          "KY",
          "LA",
          "ME",
          "MH",
          "MD",
          "MA",
          "MI",
          "MN",
          "MS",
          "MO",
          "MT",
          "NE",
          "NV",
          "NH",
          "NJ",
          "NM",
          "NY",
          "NC",
          "ND",
          "MP",
          "OH",
          "OK",
          "OR",
          "PW",
          "PA",
          "PR",
          "RI",
          "SC",
          "SD",
          "TN",
          "TX",
          "UT",
          "VT",
          "VI",
          "VA",
          "WA",
          "WV",
          "WI",
          "WY",
        ],
        upperCaseWord
      )
    ) {
      return upperCaseWord;
    }

    const forced = _.includes(FORCED_WORDS, loweredWordNoPeriod); // strip out periods so st. will match "st"
    if (
      (_.includes(IGNORED_WORDS, lowerWord) || // words we don't want to modify
        (word.match(/[aeiou]/gi) === null && wordLength > 1)) && // acronym without vowels
      !forced
    ) {
      return word;
    }

    return lowerWord.replace(
      /(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,
      (firstLetter) => {
        // eslint-disable-line
        return firstLetter.toUpperCase();
      }
    );
  });

  return formattedWords.join(" ");
}
219444
public static function camelize($word)
    {
        if (preg_match_all('/\/(.?)/', $word, $got)) {
            foreach ($got[1] as $k => $v)
                $got[1][$k] = '::'.strtoupper($v);

            $word = str_replace($got[0], $got[1], $word);
        }
        return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9^:]+/', ' ', $word)));
    }
801143
function(str) {
      if (v.isNumber(str)) {
        // If there are more than 2 decimals round it to two
        if ((str * 100) % 1 === 0) {
          return "" + str;
        } else {
          return parseFloat(Math.round(str * 100) / 100).toFixed(2);
        }
      }

      if (v.isArray(str)) {
        return str.map(function(s) { return v.prettify(s); }).join(", ");
      }

      if (v.isObject(str)) {
        return str.toString();
      }

      // Ensure the string is actually a string
      str = "" + str;

      return str
        // Splits keys separated by periods
        .replace(/([^\s])\.([^\s])/g, '$1 $2')
        // Removes backslashes
        .replace(/\\+/g, '')
        // Replaces - and - with space
        .replace(/[_-]/g, ' ')
        // Splits camel cased words
        .replace(/([a-z])([A-Z])/g, function(m0, m1, m2) {
          return "" + m1 + " " + m2.toLowerCase();
        })
        .toLowerCase();
    }
757309
function _camelcase(flag) {
  return flag.split('-').reduce(function (str, word) {
    return str + word[0].toUpperCase() + word.slice(1);
  });
}
1162154
public function regex()
    {
        // Turn "(/)" into "/?"
        $uri = preg_replace('#\(/\)#', '/?', $this->uri);

        // Create capture group for ":parameter", replaces ":parameter"
        $uri = $this->capture($uri, '/:(' . self::ALLOWED_REGEX . ')/');

        // Create capture group for '{parameter}', replaces "{parameter}"
        $uri = $this->capture($uri, '/{(' . self::ALLOWED_REGEX . ')}/');

        // Add start and end matching
        return (string) '@^' . $uri . '$@D';
    }
1169183
def camelcase(string):
    '''
    '''
    out = slug(string).replace('-', ' ').title().replace(' ', '')
    return out[0].lower() + out[1:]
592087
public static function splitWords($string)
	{
		$non_word = '\x{0000}-\x{002F}\x{003A}-\x{0040}\x{005b}-\x{0060}\x{007B}-\x{007E}\x{00A0}-\x{00BF}\s';
		if (preg_match_all('/([^' . $non_word . ']{2,})/msu', strip_tags($string), $match))
		{
			foreach ($match[1] as $i => $v) {
				$match[1][$i] = mb_strtolower($v);
			}

			return $match[1];
		}
		return [];
	}
107519
def split_camel_case(text) -> list:
    """"""
    return list(reduce(
        lambda a, b: (a + [b] if b.isupper() else a[:-1] + [a[-1] + b]),
        text,
        []
    ))
865160
protected function _compile(){
		if(!$this->regex){
			// Compile the chain
			$tokens=preg_split('#
					(?<!\\\)(
						\{[a-zA-Z_]\w+\}|
						\*|
						\+
					)
				#Ssx',
				$this->chain,
				null,
				PREG_SPLIT_DELIM_CAPTURE
			);
			$regex='';
			foreach($tokens as $token){
				$name=substr($token,1,strlen($token)-2);
				// Named slug
				if($token && $token{0}=='{'){
					$regex.='(?<'.$name.'>.*?)';
				}
				// Joker slug
				elseif($token=='*'){
					$regex.='.+?';
				}
				// Word slug
				elseif($token=='+'){
					$regex.='\w+?';
				}
				// Text
				else{
					$regex.=preg_quote(
						str_replace(
							array('\{','\*','\+'),
							array('{','*','+'),
							$token
						),
						'/'
					);
				}
				// Default value
				if(isset($this->default_values[$name])){
					$regex.='?';
				}
			}
			$this->regex="/^$regex$/Ss";
		}
		return $this->regex;
	}
1329433
static function GetRandomPassPhrase($length = 8)
	{
		srand((double)microtime()*1000000);
		
		$vowels = array("a", "e", "i", "o", "u");
		$cons = array("b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr",
			"cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "sl", "cl");
		$badwords = array("fuc","shit","ass","pus","slut","dic","fag","coc","cun","cum","dam","nig","kik","spic","neg","bitc","gay","poo","twa","vag","peni","whor");
		
		$num_vowels = count($vowels);
		$num_cons = count($cons);
		$password = "";
		
		for($i = 0; $i < $length; $i++)
		{
			$password .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)];
		}
		
		$newpass = substr($password, 0, $length);
		
		// ensure this is not a potentially offensive password
		foreach ($badwords as $badword)
		{
			if ( strpos($newpass,$badword) !== false)
			{
				return PassPhrase::GetRandomPassPhrase($length);
			}
		}
		
		return $newpass;
	}
406075
public function createRegex()
    {
        $parts = explode('/', ltrim($this->path, '/'));
        $regex = '/^'; // Matches the start of the string
        foreach ($parts as $part) {
            $regex .= '\/'; // Matches starting slash
            // Handle non-variable parts
            if (stripos($part, '{') === false &&
                stripos($part, '}') === false) {
                $regex .= $part; // Exactly match this part
                continue;
            }
            // Handle variable parts
            $name = str_ireplace(['{', '}'], '', $part);
            $this->parameterNames[] = $name;
            $this->parameters[$name] = null;
            // Check if a rule exists for this part
            if (isset($this->rules[$name])) {
                $regex .= $this->rules[$name];
                continue;
            }
            // No rule exists, match all except slashes
            $regex .= '([^\/]+)';
        }
        $regex .= '$/'; // Matches end of string
        $this->regex = $regex;
    }
643309
function borkify( $text )
    {
        $textBlocks = preg_split( "/(%[^ ]+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
        $newTextBlocks = array();
        foreach ( $textBlocks as $text )
        {
            if ( $text[0] == '%' )
            {
                $newTextBlocks[] = $text;
                continue;
            }
            $orgtext = $text;
            $text = preg_replace( "/a\B/", "e", $text );
            $text = preg_replace( "/an/", "un", $text );
            $text = preg_replace( "/au/", "oo", $text );
            $text = preg_replace( "/en\b/", "ee", $text );
            $text = preg_replace( "/\Bew/", "oo", $text );
            $text = preg_replace( "/\Bf/", "ff", $text );
            $text = preg_replace( "/\Bi/", "ee", $text );
            $text = preg_replace( "/\Bir/", "ur", $text );
            $text = preg_replace( "/\bo/", "oo", $text );
            $text = preg_replace( "/ow/", "oo", $text );
            $text = preg_replace( "/ph/", "f", $text );
            $text = preg_replace( "/th\b/", "t", $text );
            $text = preg_replace( "/\Btion/", "shun", $text );
            $text = preg_replace( "/\Bu/", "oo", $text );
            $text = preg_replace( "/\bU/", "Oo", $text );
            $text = preg_replace( "/y\b/", "ai", $text );
            $text = preg_replace( "/v/", "f", $text );
            $text = preg_replace( "/w/", "v", $text );
            $text = preg_replace( "/ooo/", "oo", $text );
            if ( $orgtext == $text )
                $text = $text . "-a";
            $newTextBlocks[] = $text;
        }
        $text = implode( '', $newTextBlocks );
        $text = preg_replace( "/([:.?!])(.*)/", "\\2\\1", $text );
        $text = "[" . $text . "]";
        return $text;
    }
1250220
function splitWords(str) {
    return str
        // insert a space between lower & upper
        .replace(/([a-z])([A-Z])/g, '$1 $2')
        // space before last upper in a sequence followed by lower
        .replace(/\b([A-Z]+)([A-Z])([a-z])/, '$1 $2$3')
        // uppercase the first character
        .replace(/^./, function(str){ return str.toUpperCase(); })
}
1052244
def __camel_case(word):
        
        word = word.lower()
        if '_' in word:
            split_word = word.split('_')
        else:
            split_word = word.split()
        if len(split_word) > 0:
            for i, word in enumerate(split_word):
                if i > 0:
                    split_word[i] = word.title()
        strings = ''.join(split_word)
        return strings
67766
protected function _compileRegex()
    {
        $raw = str_replace(' ', '', $this->dtd_regex);
        if ($raw{0} != '(') {
            $raw = "($raw)";
        }
        $el = '[#a-zA-Z0-9_.-]+';
        $reg = $raw;

        // COMPLICATED! AND MIGHT BE BUGGY! I HAVE NO CLUE WHAT I'M
        // DOING! Seriously: if there's problems, please report them.

        // collect all elements into the $elements array
        preg_match_all("/$el/", $reg, $matches);
        foreach ($matches[0] as $match) {
            $this->elements[$match] = true;
        }

        // setup all elements as parentheticals with leading commas
        $reg = preg_replace("/$el/", '(,\\0)', $reg);

        // remove commas when they were not solicited
        $reg = preg_replace("/([^,(|]\(+),/", '\\1', $reg);

        // remove all non-paranthetical commas: they are handled by first regex
        $reg = preg_replace("/,\(/", '(', $reg);

        $this->_pcre_regex = $reg;
    }
1057472
function get_tops($limit = 10, $xattr = '') {
        $ret = array();
        if (!$this->_txt) return false;
        $xmode = false;
        $attrs = array();
        if ($xattr != '') {
            if (substr($xattr, 0, 1) == '~') {
                $xattr = substr($xattr, 1);
                $xmode = true;
            }
            foreach (explode(',', $xattr) as $tmp) {
                $tmp = strtolower(trim($tmp));
                if (!empty($tmp)) $attrs[$tmp] = true;
            }
        }

        // save the old offset
        $off = $this->_off;
        $this->_off = $cnt = 0;
        $list = array();
        while ($tmpa = $this->get_result()) {
            foreach ($tmpa as $tmp) {
                $tmp['attr'] = trim($tmp['attr']);
                if ($tmp['idf'] < 0.2 || substr($tmp['attr'], 0, 1) == '#') continue;
                // check attr filter
                if (count($attrs) > 0) {
                    if ($xmode == true && isset($attrs[$tmp['attr']])) continue;
                    if ($xmode == false && !isset($attrs[$tmp['attr']])) continue;
                }
                // check stopwords
                $word = strtolower($tmp['word']);
                if ($this->_rule_checkbit($word, PSCWS4_RULE_NOSTATS)) continue;
                // put to list
                if (isset($list[$word])) {
                    $list[$word]['weight'] += $tmp['idf'];
                    $list[$word]['times']++;
                } else {
                    $list[$word] = array('word' => $tmp['word'], 'times' => 1, 'weight' => $tmp['idf'], 'attr' => $tmp['attr']);
                }
            }
        }
        // restore the offset
        $this->_off = $off;
        // sort it & return
        if ( (float)substr(PHP_VERSION, 0, 3) >= 5.3 ) {
            $cmp_func = function($a, $b) {return ($b['weight'] > $a['weight'] ? 1 : -1);};
        } else {
            $cmp_func = create_function('$a,$b', 'return ($b[\'weight\'] > $a[\'weight\'] ? 1 : -1);');
        }

        usort($list, $cmp_func);
        if (count($list) > $limit) $list = array_slice($list, 0, $limit);
        return $list;
    }