简体   繁体   中英

Getting value from MathQuill

I am using MathQuill I would like to get the values of the fraction I got it using Split which wasn't robust !

var str="\frac{12}{3}+\frac{2}{3}";

How to get the values of a fraction using JavaScript ! I found that I should use regrex ! I am new to javascript regrex ! I want values as

var fra1=12;
var fra2=3;
var fra3=2;
var fra4=3;

If you have to use regex, and you only need it for this particular string, then the simplest method is to use .match and convert to number:

 const str = "\\frac{12}{3}+\\frac{2}{3}"; const frasStrings = str.match(/\\d+/g); const frasNumbers = frasStrings.map(Number); console.log(frasNumbers); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM