Hello, I've some string (char *) in C
and using sscanf
to tokenize it.
I'm generating C
source-code and using sscanf
is easiest solution, however there is this problem:
There is regular expression for parameter:
[$]([a-zA-Z0-9_-]{0,122})?[a-zA-Z0-9]
(Starting with $
, can contain numbers
, letters
, '-'
and '_'
, but later two can not be at the end of parameter name.)
i.e. :
$My_parameter1 //OK
$my-param-2 //OK
$_-this_-_is--my-_par //OK
$My_parameter2- //WRONG!
$My_parameter2_ //WRONG!
Problem is this (simplified):
char _param1 [125]; //string that matches parameter name
char _param2 [125]; //string that matches parameter name
if ( sscanf(str, " $%124[a-zA-Z0-9_-] - $%124[a-zA-Z0-9_-] ", _param1, _param2) != 2 )
DO_FAIL;
When used on " $parameter_one - $param-two "
it works (clearly).
Problem is obviously with "$param1-$param2"
, because sscanf tokenizes first item as '$param1-
' and then fails to find '-'
.
Can experienced C
programmer see how to simply solve this?
i.e.:
char _param1 [125]; //string that matches parameter name
char _param2 [125]; //string that matches parameter name
??? ... ???
sscanf("$my-param1-$my-param2", ??? ... ???)
??? ... ???
// _param1 == "$my-param1" //resp. strcmp(_param1, "$my-param1") == 0
// _param2 == "$my-param2"
Thanks...