正则表达式查找替换[关闭]

i am new to regex in PHP, and had a question

What i am trying to do (in PHP):

  1. Find whether a string contains special characters or non-alphabets in a name (e.g. if term contains -, *, ., &, etc)
  2. If string contains special characters - find and replace it using str_replace. Sample strings include 'e*trade', 'e-trade', 'Barnes&Noble', etc.

Replace Symbols only

<?php
$regex = "/[-*.&]/";
$subject = "Barnes&Noble";
$replacement = "-";
$result = preg_replace($regex, $replacement, $subject);
echo $result;

Output:

Barnes-Noble


Replace all parts of the string if it matches Symbols:

<?php
$regex = "/(.*)([-*.&])(.*)/";
$subject = "Barnes&Noble";
$replacement = "$1 is not so $3";
$result = preg_replace($regex, $replacement, $subject);
echo $result;

Output:

Barnes is not so Noble


http://ideone.com/ByXagy