0
내가) 평가 (뭔가를 쓰기 위해 노력하고있어, 여기에 요구 사항 중 일부입니다 :regex는 개별적으로 작동하지만 |
if the expression contains non-numeric character other than [+, -, *, /, .],
or [+, -] is followed by [*, /],
or [+, -, *, /] is not proceeded by a numeric e.g."10-",
or [*, /] is not preceded by a numeric e.g."-10" is valid, "*10" is not valid
throw an exception
나는 다음과 같은 코드가 있습니다
if (expression.match(/[^+\-*/\d.]/) ||
expression.match(/[+-](?=[*/])/) ||
expression.match(/[+\-*/]($|[^+\-.\d])/) ||
expression.match(/(^|[^+\-.\d])[*/]/))
throw errors.ExpressionParserError;
잘 작동 표현은 다음과 같이 구분 그러나 이들을 | (OR)와 결합하면 더 이상 예외가 발생하지 않습니다.
if (expression.match(/[^+\-*/\d.] | [+-](?=[*/]) | [+\-*/]($|[^+\-.\d]) | (^|[^+\-.\d])[*/]/))
throw errors.ExpressionParserError;
예 : "d * 1"은 [^ + - */\ d] 표현의 첫 부분에 있어야합니다.
여기서 무엇을 놓쳤습니까? 감사.
감사! 공백을 삭제 한 후에 작동했습니다. – cx0618