I have some string data that I need to search through to find a specific number:
Here's a sample string/buffer:
Conference 11-2222-a.b.c (1 member rate: 32000 flags: running|answered|enforce_min|dynamic|exit_sound|enter_sound) 176;014802813@mydomain;0182e4e4-193b-4d63-9bef-b597f0655c83;jdo ;014802813;hear|speak|talking|floor;0;0;0;0
Conference 10-1234.c.fdf.c (1 member rate: 32000 flags: running|answered|enforce_min|dynamic|exit_sound|enter_sound)175;.net/4122@mydomain;77c1f301-85e1-4275-9c539e5927b87d6;4122;hear|speak|talking|floor;0;0;0;0
What I need to do is search through this output and the 4 digits that follow "Conference 10-". In this case it is 1234 that I'm after.
**What I've tried **
I've tried all the following patterns... none of which are giving me what I need:
print(string.match(input, "10-%d%d%d%d-"));
print(string.match(input, "Conference 10-%d%d%d%d-"));
print(string.match(input, "Conference 10-(%d)-");
print(string.match(input, "Conference 10(\-)(%d));
You need to escape the hyphen with %
as unescaped -
is a lazy quantifier in Lua (-
also 0 or more repetitions).
str = "Conference 11-2222-a.b.c (1 member rate: 32000 flags: running|answered|enforce_min|dynamic|exit_sound|enter_sound) 176;014802813@mydomain;0182e4e4-193b-4d63-9bef-b597f0655c83;jdo ;014802813;hear|speak|talking|floor;0;0;0;0\n\nConference 10-1234.c.fdf.c (1 member rate: 32000 flags: running|answered|enforce_min|dynamic|exit_sound|enter_sound)175;.net/4122@mydomain;77c1f301-85e1-4275-9c539e5927b87d6;4122;hear|speak|talking|floor;0;0;0;0"
print(string.match(str, 'Conference 10%-(%d%d%d%d)') )
^
This will print 1234
.
From the Lua 20.2 – Patterns reference:
Some characters, called magic characters, have special meanings when used in a pattern. The magic characters are
( ) . % + - * ? [ ^ $
The character
%
works as an escape for those magic characters.