使用正则表达式模式lua

时间:2018-08-13 15:51:25

标签: regex lua pattern-matching lua-patterns

我有一个休息URL作为字符串-> rest/dashboard/person/hari/categrory/savingaccount/type/withdraw

在这种情况下,我必须获得人员和类别之间的值以及类别和类型之间的值。因为这些值会动态变化

休息/仪表板/人/ {{}} /类别/ {{}} /类型/退出

我尝试了string.gsub(mystring, "([%w]+%/)([%w%d]+)")。但这似乎不是正确的浪费

请帮助

2 个答案:

答案 0 :(得分:3)

string.match(具有捕获功能)是完成任务的正确工具。 试试这个:

s="rest/dashboard/person/hari/category/savingaccount/type/withdraw" 
print(s:match("/person/(.-)/category/(.-)/type/"))

答案 1 :(得分:2)

您可以按照建议使用惰性点Private Sub Text757_Click() Dim Remarks757 As Variant Remarks757 = DLookup("Remarks", "QueryDataPaveAll", "[YrRated] = Forms![FormDataEntryPave]![TextYrRated]" And "[RdSecNo] = Forms![FormDataEntryPave]![TextRdSecNo]") If IsNull(Remarks757) Then MsgBox "No Record Found" Else Me.Text757 = Remarks757 End If End Sub 或否定的字符类.-

[^/]+

Demo