我想刪除-
後的所有內容。如何刪除指定字符後的所有內容
這裏是我的樣品string
:sahasraadvisoryagency - a service agency
我的預期輸出:sahasraadvisoryagency
我的測試用例:
sahasraadvisoryagency - a service agency
輸出:sahasraadvisoryagency
chai chai - a tea service
輸出:chai chai
paani wala + neerwal - a water service
輸出:paani wala + neerwal
我試圖像這樣
var str = 'sahasraadvisoryagency - a service agency';
var newstr = str.replace(/\-/g,'');
console.log(newstr);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>