1

I have string look like this :

"fdsgsgf.signature=xxxxx(bv)"

And i want to get xxxxx

With : var testRE = html.match(".signature=(.*)/\(");

And when i run it i get exception that it's not valid regex.

Any idea why?

3
  • non regex solution.. html.split("=")[1].split("(")[0].. can make better though. Commented Sep 30, 2013 at 14:10
  • 1
    What is the point of your forward slash? Commented Sep 30, 2013 at 14:11
  • Use a regular expression literal instead of a string literal. Commented Sep 30, 2013 at 14:12

2 Answers 2

2

Some issues with your code:

  • You're missing starting slash / of your regex
  • Instead of .* you should better use [^(]+
  • dot needs to be escaped

Modified code:

html.match(/\.signature=([^(]+)/);
Sign up to request clarification or add additional context in comments.

3 Comments

Won't this match the slash since it's a string literal? (Didn't downvote btw)
The / isn't missing. If you use a string then you don't have the slashes.
@JamesMontagne: I am talking from regex perspective since OP tagged question with regex
2

You need to double escape the backslash: ".signature=(.*)/\\(". This is a valid regex, but it will match the / char though. If you don't need it, simply remove it ;)

1 Comment

Can you give me example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.