3

I have a silverlight application that i am converting to html5. I have this piece of code in c# that i am having trouble converting to javascript equivalent.

C#:

private const String DELIMITERS = @"(?=[,'\s])|(?<=[,'\s])";
string[] searchList = Regex.Split(MainTextArea.Text, DELIMITERS);

This is what i have tried in javascript but it's not splitting text.

javascript:

var searchList = $input.val().split("(?=[,'\\s])|(?<=[,'\\s])");

Thanks for any help in advance.

4
  • 3
    That’s because lookbehinds aren’t supported in JS. Commented Jul 20, 2016 at 20:33
  • OK so what would be the solution? Is this possible in javascript? Commented Jul 20, 2016 at 20:47
  • Here's an answer that works around javascript not supporting lookbehinds. Also regular expressions are enclosed between / so you'll want to update your javascript to reflect $input.val().split(/(?=[,'\\s])/); Commented Jul 20, 2016 at 20:54
  • Could you replace each of the delimiters with a single delimiter and then split on that? Commented Jul 20, 2016 at 21:09

1 Answer 1

1

So the following ended up being the javascript equivalent:

$input.val().split(/([,'\s])+/);

Thanks for the helpful comments

Sign up to request clarification or add additional context in comments.

Comments

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.