<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <p>What i have</p> <input value="1475g - 1500g" /><br> <p>what do i need.</p> <input style="width:50px;" value="1475" /><span>g - </span><input style="width:50px;" value="1500" /><span>g</span> </body> </html>Usa dividir y reemplazar.
const input = document.querySelector("input").value; // add an ID or class or something, this is just for demo purposes const [ seperated1, seperated2 ] = input.replace(/g/g, "").split(" - "); // First regular expression removes all "g"s from the string. Split turns the string into an array using " - " as a delimiter console.log(seperated1, seperated2);Utilizar este:
let val = '1475g - 1500g'; val = val.replace(/g| /g, ''); val = val.split('-'); console.log(val[0], val[1]);