Answer the question
In order to leave comments, you need to log in
How to find and determine a number in a string?
Hello.
The definition of the number in Value does not work for me.
The data is read from the test.jem file, transferred to the lexems.js file, and the format is determined for the one in brackets.
( test.jem )
print(56); // Число
print(hello); // Чтобы проверялась ошибка
print("hello world"); // Строка
print( ); // Пустое значение
if (/print \((.*)\)/gim.test(copyString)) { // Находим что если скобочки без кавычек это число
let num = copyString.replace(/print \((.*)\)/gim, '$1'); // Убираем принт и скобочки
if ((typeof num) === 'string') { // Определение TypeError
stringObject["TypeError"] = num;
console.log(`TypeError: ${num} is not a Number. ${num} is String`);
}
}
Answer the question
In order to leave comments, you need to log in
num = Number(copyString.match(/\((.*)\)/)[1] || undefined)
if(!isNaN(num)) { console.log('это число!') }
copyString = 'print ("hello world"); //строка'
// undefined
copyString = 'print (56); '
// это число!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question