다음은 매우 간단한 정규식 코드로, php와 ruby에서는 올바르게 작동하지만 JS에서는 작동하지 않습니다. 내가 작동하도록 도와주세요.
var r = /:[a-z]+/
var s = '/a/:b/c/:d'
var m = r.exec(s)
// now m is [":b"]
// it should be [":b", ":d"]
// because that's what i get in ruby and php
RegExp 사용 . exec()
with g
(global) modifier는 모든 일치 항목을 얻기 위해 루프 내에서 사용됩니다.
var str = '/a/:b/c/:d'
var re = /:[a-z]+/g
var matches;
while (matches = re.exec(str)) {
// In array form, match is now your next match..
}
String을 사용할 수도 있습니다 . match()
여기에 방법.
var s = '/a/:b/c/:d',
m = s.match(/:[a-z]+/g);
console.log(m); //=> [ ':b', ':d' ]
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다