export interface ValueParserResult {
value: number,
error: string
}
interface subParseResult {
result: (string | number) [],
error: string
}
class ValueParser {
parse(eq: string, values: {[key: string] : number}, level?: number) : ValueParserResult {
const result: ValueParserResult = { value: 0, error: "" }
const numberRe: RegExp = /([^|\(||/|/\-|-|\*|\*\-|+|\^])+([0-9.]*)([$|(|)|/|/-|-|*|*-|+|])+/g;
const eqParse = eq.split(" ").join('');
eqParse.replace(numberRe, (matched) => {
return " ," + matched;
})
console.log(eqParse)
return result;
}
}
const vp = new ValueParser();
const values = {a: 22, b:-10, c: 5}
const eq = "123/456*82*(a+b/c)"
vp.parse(eq, values)
This captures the entire eqParse
string and puts a space comma in front of it. I want to put the comma space before each value and not capture the strings before and after.