1

having problems with regex in javascript.

need to parse out all variables from a String which include a letter.

As far i used /[0-9\][A-Za-z.]*/g gives me wrong results.

Sample:

windo.w029384-(2*I00983.size)+23.8/6+ss-t

need to parse out windo.w029384, I00983.size, ss, t

Thanks for help.

2 Answers 2

1

You can use:

'windo.w029384-(2*I00983.size)+23.8/6+ss-t'.match(/[a-z][\w.]*/ig);
//=> ["windo.w029384", "I00983.size", "ss", "t"]
Sign up to request clarification or add additional context in comments.

2 Comments

I think /[a-z][\w.]*/ig would be more concise and better suited since variables can definitely use underscores and the OP is simply trying to detect variables. What about the alternate form of var.key, var["key"] or var['key'], or even var[key]?
Totally agree on \w but for other forms of input OP needs to specify more examples.
0

How about /[\w.]+/g? \w includes [0-9] and [A-Za-z]

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.