내가 만 단어를 유지하는 배열정규식 도움 분할 문자열
"Test [email protected],@[email protected],@Test [email protected],@10001"
에이 문자열을 분할 할, 나머지는 멀리 갈 수 있습니다. 그래서 나는 결국
[ "Test One", "Test Two" ]
으로 끝날 것입니다.이 정규 표현식은 나를 피할 수 있습니다. 어떤 도움?
내가 만 단어를 유지하는 배열정규식 도움 분할 문자열
"Test [email protected],@[email protected],@Test [email protected],@10001"
에이 문자열을 분할 할, 나머지는 멀리 갈 수 있습니다. 그래서 나는 결국
[ "Test One", "Test Two" ]
으로 끝날 것입니다.이 정규 표현식은 나를 피할 수 있습니다. 어떤 도움?
그게 당신이하고있는 모든 있다면, 내가 대신 분할을 사용합니다 :
>>> "Test [email protected],@[email protected],@Test [email protected],@10001".split('@,@');
["Test One", "10000", "Test Two", "10001"]
어떤 방법 string.split(..)
대해를?
var split_array = "Test [email protected],@[email protected],@Test [email protected],@10001".split("@[email protected]");
var string = "Test [email protected],@[email protected],@Test [email protected],@10001";
var array = string.match(/([a-z\s]+)/ig); // ["Test One", "Test Two"]
이에 대한 정규식이 필요하지 않습니다. 표준 문자열 함수를 사용할 수 있습니다. (모든 요소뿐 아니라 단어를 반환) 레너드 Challis '답변을 구축, 당신은 같은 것을 할 수 있습니다
var myStrings = "Test [email protected],@[email protected],@Test [email protected],@10001".split('@,@');
var splitList = [];
var i = myStrings.length;
while(i--) {
if(IsNaN(myStrings[i])) splitList.push(myStrings[i]);
}
splitList
는 이제 단어를 포함, 당신이 요구 구체적으로 무엇이다. 내용은 다음과 같습니다.
["Test One", "Test Two"]
요청하신 내용은 다음과 같습니다.
당신이 이기고, 감사합니다! :) – Pr0FiT
아주 작은 성능을 얻으려면 다음과 같이 RegEx에서 괄호를 제거하는 것이 좋습니다 :'var array = string.match (/ [a-z \ s] +/ig); – JamieJag