Sunday 15 January 2012

javascript - Regex splitting on parenthesis, first uppercase, and digits -


Now, I have a chemical formula input, say q (NO3) 2, and divide the elements and numbers into one Array This code works for all the sources, apart from the addition of parentheses. (Which actually came from the deposit bag from the user here.)

  var userArray = userIn.replace (/ \ d + / g, '~ $ & amp;'). Partition (/ (? = [AZ]) | ~ /);   

The reason I used to be used was to split then to make sure that if someone enters H12, then it is H, 12, instead of H, 1, 2 will come out in the form of

I want q (, n, o, 3), 2 ... when actually ... well, (, n, o, 3,), 2

About using a match instead of the G flag:

  var userArray = userIn.match (/ (?: [AZ] [az] * | \ d + | [()]) / g);    

No comments:

Post a Comment