1

I have a text:

$D('make').onChange('s',123456789,'a',10)

The target is to get values 123456789 and a

Please help to create regex expression to parse a string.

ps Im using javaScript but i think at all laguages the result will be the same.

Thanks!

3
  • Split by comma and take 1st and 2nd index elements. Commented Nov 26, 2014 at 10:26
  • thats good solution! but the task is to use regex. sorry Commented Nov 26, 2014 at 10:28
  • Don't feel sorry, split also uses regex i.e. /,/g Commented Nov 26, 2014 at 10:29

2 Answers 2

2

Through string.split function.

> var s = "$D('make').onChange('s',123456789,'a',10)";
undefined
> s.split(/,'?|'?,/)[2]
'a'
> s.split(/,'?|'?,/)[1]
'123456789'
Sign up to request clarification or add additional context in comments.

1 Comment

This solution is better becouse number may contain more or less numbers? for example 112 or 55555555555. So thanks a lot!
0
var res = str.match(/,(\d{9}),\'([a-z]{1})\'/);

console.log(res[1]);
console.log(res[2]);

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.