Помощь - Поиск - Пользователи - Календарь
Полная версия: Извлечь отрицательные числа из строки / Extract negative numbers from string
UoKit.com Форумы > Кликер > UO Pilot
neves
I have problem with extracting negative number from given string.
In the uopilot wiki I found this example:
Код
--lua
local str1 = "Координаты: X = 360, Y = 638"      -- строка
local num1, num2 = string.match(str1, "(%d+)[^%d]+(%d+)")    -- найти 2 числа, между числами могут присутствовать любые символы
log(num1, num2)

but, (%d+) extract the numbers and doesn't check if there's "-" sign before the found case.
Is there any other regex to use instead?
Also I'm sorry if there's already such a topic in the forum, but I can't use the search engine, because forum is mostly russian.
neves
Solved.
Код
--lua
local str1 = "Coordinates: X = -360, Y = -638"
local num1, num2 = string.match(str1,"(%-?%d+)[^%d]-(%-?%d+)")
log (num1, num2)
Это текстовая версия — только основной контент. Для просмотра полной версии этой страницы, пожалуйста, нажмите сюда.
Русская версия Invision Power Board © 2001-2024 Invision Power Services, Inc.