JavaScript Regex splitting on parenthesis, first uppercase, and digits regex split parentheses,regex split parentheses java,regular expression split

Right now, I have the user inputting a chemical formula, say Cu(NO3)2, and splitting the elements and numbers into an array. This code works for all formulas except for those with parentheses. (which actually came from a user-submitted thread on here.)

var userArray=userIn.replace(/\d+/g, '~$&').split(/(?=[A-Z])|~/);

The reason I used replace then split was to ensure that if someone entered H12, it would come out as H , 12 ... rather than H , 1 , 2.

I'm getting Cu( , N , O , 3) , 2 ... when in fact I want... Cu , ( , N , O , 3 , ) , 2

Answer:1

What about using match instead with the g flag:

var userArray=userIn.match(/(?:[A-Z][a-z]*|\d+|[()])/g);
Answer:2

You need to add the parentheses into your replace pattern, like so:

var userArray=userIn.replace(/\d+|\(|\)/g, '~$&').split(/(?=[A-Z])|~/);
Answer:3

The following script pulls the data from my database and creates a pagination. The pagination works, but I would like to add a conditional statement which differentiates the level of the user. User ...

The following script pulls the data from my database and creates a pagination. The pagination works, but I would like to add a conditional statement which differentiates the level of the user. User ...

  1. pagination conditions cakephp
  2. laravel pagination conditions
  3. cakephp 3 paginate conditions

I'm trying to build a Rock Paper Scissors game in JavaScript, but also have it where the computer outputs images to the HTML document. I've tried everything I know, and it won't work. Here's the HTML: ...

I'm trying to build a Rock Paper Scissors game in JavaScript, but also have it where the computer outputs images to the HTML document. I've tried everything I know, and it won't work. Here's the HTML: ...

  1. make images change automatically html
  2. how to make images change in html
  3. how to make images change in javascript
  4. make a change images
  5. how to make images change in powerpoint
  6. how to make images change in css
  7. how to make images change on website
  8. make background change images
  9. make background change images css

Is it possible in Javascript to convert something like this: d131dd02c5e6eec4 693d9a0698aff95c 2fcab58712467eab 4004583eb8fb7f89, which is the result of an MD5 hash function, into an integer ?

Is it possible in Javascript to convert something like this: d131dd02c5e6eec4 693d9a0698aff95c 2fcab58712467eab 4004583eb8fb7f89, which is the result of an MD5 hash function, into an integer ?

  1. javascript convert hash to array
  2. javascript convert hash to string
  3. javascript convert hash to json
  4. javascript convert hash to query string
  5. javascript convert hash to url
  6. js convert hash to array
  7. javascript convert to hash
  8. javascript convert to hash code
  9. javascript convert object to hash
  10. javascript convert string to hash number
  11. convert hashtable to string javascript

Context: HTML web page (jade/node.js/javascript) image url has strings with spaces/non-ascii characters I need to encode these strings either with escape or urlencode. as of now I am using escape to ...

Context: HTML web page (jade/node.js/javascript) image url has strings with spaces/non-ascii characters I need to encode these strings either with escape or urlencode. as of now I am using escape to ...

  1. javascript escape urlencode
  2. js escape urlencode
  3. javascript escape vs urlencode
  4. javascript url encode escape