를 트림의 기본 브라우저 구현을 사용할 수 있도록하고 있습니다 오른쪽 정렬 된 문자열 및 사용자의 상태 필드를 업데이트하는 방법에 대해 설명합니다. 이 당신에게 관심이있을 수 있습니다
/
과 관련하여
<html>
<head>
<script>
//option 1: just determine if the string is valid
string_valid = function (str) {
validity_indicator = {
true:"Valid",
false:"InValid",
};
return validity_indicator[str.match(/\s*([^\s](:?.*[^\s])?)\s*/) != null];
};
// option 2: the trim and validation sort of wrapped up in one.
parse_for_validity = function (str) {
if ((result = /\s*([^\s](:?.*[^\s])?)\s*/.exec(str)) == null) {
return 'Incorrect';
}
return result[ 1 ];
};
// then either
// errmsg.innerHTML = string_valid(your_string_here)
</script>
</head>
<body>
<!-- and then test them out -->
<script>
alert(string_valid(" ")); // => 'Incorrect'
alert(string_valid(" abc ")); // => 'Correct'
alert(parse_for_validity(" ")); // => 'Incorrect'
alert('...' + parse_for_validity(" abc ") + '...'); // => '...abc...'
</script>
</body>
</html>
, 당신은 당신이 당신의 정규 표현식 내에서 그것을 사용하는 경우 그것은 자신을 염려해야한다 생각합니다. 당신이 테스트하고있는 문자열에 /
을 가지고 있다면 괜찮습니다. 당신이 당신의 정규 표현식에 /
을 테스트하려면, 다음과 같은 식으로,이 \/
처럼 탈출 할 수 있어야한다 : /\//
도움이 되었기를 바랍니다. 나는 정규 표현식을 좋아한다! :)
는
답변 해 주셔서 감사합니다. Scurker Answer는 내가 찾고있는 것입니다. 그래서이 대답을 가장 좋은 대답이라고 부릅니다. – BruceyBandit