내가 같은 문자열이 있다고 가정하면 $foo$bar$baz $5
문자열을`$ '로 배열로 분할 한 다음 첫 번째와 두 번째 요소를 제거한 다음 배열을 새 문자열로 변환하려고했습니다. 하지만 더 우아한 방법이 있는지 궁금합니다.
의 처음 두 항목 $
과 빈 문자열이있는 일부 텍스트를 제거 할 수 있습니다.
^(\$[^$]+){2}\$ regular expression ^ start of the string \$ search for $ literally [^$] search for any character but not $ + quantifier one or more ( ) group {2} quantifier for exactly two times ( ){2} get the group only two times \$ get the third $
var string = '$foo$bar$baz $5',
result = string.replace(/^(\$[^$]+){2}\$/, '');
console.log(result);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다