admin管理员组

文章数量:1430036

I have problem as below:

var test = $("#k_w").val().search("sinh("+parseFloat(sinh_array[i]));

The debugger shows an error: Uncaught SyntaxError: Invalid regular expression: /sinh(2/: Unterminated group.

sinh_array[i] are numbers.

What's wrong?

I have problem as below:

var test = $("#k_w").val().search("sinh("+parseFloat(sinh_array[i]));

The debugger shows an error: Uncaught SyntaxError: Invalid regular expression: /sinh(2/: Unterminated group.

sinh_array[i] are numbers.

What's wrong?

Share Improve this question edited Mar 18, 2012 at 21:14 Rob W 349k87 gold badges807 silver badges682 bronze badges asked Mar 18, 2012 at 13:09 Marcin KostrzewaMarcin Kostrzewa 5954 gold badges11 silver badges24 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

The String.search method converts the first argument to a Regular expression.

You are looking for the String.indexOf method, which search for a string, without a conversion to a RegExp.

var test = $("#k_w").val().indexOf("sinh("+parseFloat(sinh_array[i]));
//                         ^^^^^^^ indexOf

You have an opening parenthesis in your regex, but no closing parenthesis.

I think what you really want is this:

var test = $("#k_w").val().search("sinh\\("+parseFloat(sinh_array[i]) + "\\)");

I suspect you want to match the actual parens, and not create a group.

You have to escape parentheses in regexps; otherwise they begin a match group and thus have to be closed again.

var test = $("#k_w").val().search("sinh\\("+parseFloat(sinh_array[i]));

本文标签: javascriptError when using Stringsearch(quotsinh(2quot) quotInvalid regular expressionquotStack Overflow