regex - regular expression - replace a word by a space -
i have line , wants replace not dots , underline space. now replace word "german" (without quotes) blank line.
can ?
preg_replace('/\(.*?\)|\.|_/i', ' ',
best regs
edit:
public function parsemoviename($releasename) { $cat = new category; if (!$cat->ismovieforeign($releasename)) { preg_match('/^(?p<name>.*)[\.\-_\( ](?p<year>19\d{2}|20\d{2})/i', $releasename, $matches); if (!isset($matches['year'])) preg_match('/^(?p<name>.*)[\.\-_ ](?:dvdrip|bdrip|brrip|bluray|hdtv|divx|xvid|proper|repack|real\.proper|sub\.?fix|sub\.?pack|ac3d|unrated|1080i|1080p|720p|810p)/i', $releasename, $matches); if (isset($matches['name'])) { $name = preg_replace('/\(.*?\)|\.|_/i', ' ', $matches['name']); $year = (isset($matches['year'])) ? ' ('.$matches['year'].')' : ''; return trim($name).$year; } } return false; }
the string example "moviename german 2015" output should "moviename 2015" (without quotes)
solved:
change line preg_replace('/\(.*?\)|\.|_/i', ' ', $matches['name']);
$name = preg_replace('/\h*\bgerman\b|\([^()]*\)|[._]/', ' ', $matches['name']);
thanks @ wiktor stribiżew
to add alternative alternation group, need use
$name = preg_replace('/\h*\bgerman\b|\([^()]*\)|[._]/', ' ', $matches['name']); ^^^^^^ ^^^^^^^
note \h
matches horizontal whitespace (no linebreaks), if need linebreaks, use \s
.
the \h*\bgerman\b
matches 0 or more spaces followed whole word "german" (as \b
word boundary, no "germanic" word matched).
also, (\.|_)
equal [._]
in result pattern matches, character class [...]
more efficient when matching single symbols.
Comments
Post a Comment