xenophobia Posted August 25, 2009 Share Posted August 25, 2009 Hi. I wanna do some matching with returning the desired data i want. Let's start the example. var string = ":name=Kent Lee"; Im actually doing a command based program where user will key-in some console like command. It's simple, everything start with colon (, will be a command followed by the property name and the value after the equal sign. var regex = new RegExp(/^:\S=.*$/ig); document.writeln(regex.test(string)); the above regex will match and return true if user enter a command. What I want is, can I use the regex to return me: [name, Kent Lee]. The property name and the value. I know in PHP using preg can do something like that. I just wonder in javascript is it possible?? Quote Link to comment Share on other sites More sharing options...
Adam Posted August 25, 2009 Share Posted August 25, 2009 Yeah it's possible. I'd just use the match() method though instead. Consider the following... var matches = str.match(/your regex/); If you add the 'g' modifier it will match more than once. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.