LUA:如何查找和匹配文件名

时间:2016-06-13 14:09:13

标签: lua

我有一个名为medicine_NU12345.pdf的文件。我想从pdf文件名中提取NU12345。我怎么能用Lua做到这一点。

我能够做一个string.find('NU')但是如何包含它来查找数字。每个文件的数字都会改变

1 个答案:

答案 0 :(得分:1)

使用template <typename T> class Iterator : public std::iterator<std::forward_iterator_tag, { public: Iterator(TreeNode<T>* root) { this->current = root; } template <typename T> bool operator!=(Iterator<T> const & other) const { return this->current != other.current; } template <typename T> T &operator*() const { return current->element; } Iterator operator++() { current = current->nextInorder(); return *this; } Iterator operator++(int dummy) { TreeNode<T> temp = current; current = current->nextInorder(); return *temp; } private: TreeNode<T>* current; void nextInorder() { if (current->element == NULL)return; else { nextInorder(current->left); nextInorder(current->element); nextInorder(current->right); } } }; 和正则表达式:

string.match

或者,使用result = string.match(filename, "NU[%d]+") 返回匹配的开头和结尾,然后取一个子字符串:

string.find