Say I have a pattern, and a string:
String = "ABCDEF"
Pattern = "%w%w%w - %w%w%w"
How can I make String match the format of Pattern, so it becomes "ABC - DEF"?
Say I have a pattern, and a string:
String = "ABCDEF"
Pattern = "%w%w%w - %w%w%w"
How can I make String match the format of Pattern, so it becomes "ABC - DEF"?
On
There no one to one match beetween string, pattern and capture.
Same capture can be produced by several patterns for same string.
Also if "%w%w%w - %w%w%w" in your example is Lua string pattern then
string "ABC - DEF" does not match to it. Patterns that match to it can be
%w%w%w %- %w%w%w or %w+%W+%w+ or %w*%s*.%s*%w* or several others.
So I suggest define your own subset of rules that you really need and
implement your own function to handle it.
Use
string.gsub:Note that this would replaces all the occurrences of the pattern.