Chikwado Posted January 16, 2016 Share Posted January 16, 2016 (edited) Some one help view this: I was hoping that this script would work, It some how behave as it work. code This is what want to do with that script: In textarea I will type my bla bla phrase then in the text field i will type regexp pattern and the script will pass the match to new div. Ok, for example if i type "hello world" in the textarea i will type this /world/i; to match world. Then it stop working. But if i remove this character //i; it start to return the match Edited January 17, 2016 by Chikwado Link to comment Share on other sites More sharing options...
justsomeguy Posted January 18, 2016 Share Posted January 18, 2016 The text is just a string, not a regular expression pattern. If you type "/world/i;", then it is looking for "/world/i;", not "world" with the i modifier. You can try to parse the text to get the delimiters, pattern, and flags and then create a RegExp object and pass that to match. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp Link to comment Share on other sites More sharing options...
ShadowMage Posted January 20, 2016 Share Posted January 20, 2016 I was going to say you could use eval on the string to turn it into a regexp, but that probably wouldn't be a good idea to use on a user input field. Link to comment Share on other sites More sharing options...
Chikwado Posted January 25, 2016 Author Share Posted January 25, 2016 You can parse the text to get the delimeter, pattern and flags and create regular expression object I don't know how to do that, Can you help me do it? I like to type my phrase in the textarea and input pattern in text field to match some word. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 25, 2016 Share Posted January 25, 2016 If you're counting on "/" being the delimiter, then use something like String.split to split the text up and get the various parts. See the MDN documentation for how to create a RegExp object. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now