![]() |
|
[C] String Pattern Match in C - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] String Pattern Match in C (/showthread.php?tid=4553947) |
String Pattern Match in C - geekmorpheus403 - Nov 24, 2014 Hello HF, So i am tying to match a pattern in a string.And extract a word for the string. For example: In a huge string I want to search for, "admin-* admin-1" I want to search for this pattern in a huge array and the * can be anything.And if the pattern matches.I want to get the value *. As in if the string was "admin-lotty admin-1" I want to get the word "lotty".Can somebody please help me with it and show me how to do it please. Best Regards, geekmorpheus403 * - Archimedes - Nov 24, 2014 If you have some basic C++ knowledge you can probably end up writing something like this. I'd recommend starting by writing a program that actually matches the exact string and then go from there. Don't try to take in the entire problem at once, split it up into parts and work on it. * - Trip2nite - Nov 25, 2014 Code #include <iostream>* - -ceramic- - Nov 25, 2014 He asked for a C solution. Try hxxps://github.com/cesanta/slre Examples included on the frontpage. * - Mouse❤️ - Nov 25, 2014 Guy asks for help learning something community posts code without explanation (in wrong language this time.) "Why do people think HF is a joke??? Isn't what we're doing right?"
* - geekmorpheus403 - Nov 26, 2014 (Nov 25, 2014 04:47 AM)-ceramic- Wrote: He asked for a C solution. Thanks man.But it is working fine with small string.But in for huge string(60000) characters it is not ending for some reason.I left it for hours but the program never stops. Can you help? * - 0xDEAD10CC - Nov 27, 2014 Code #include <stdio.h>Simple example. Are you looking for multiple occurrences? Also, you'll have to use other functions to search for the index of 'admin-' in the buffer. If you're paranoid that your buffer size might not be large enough, then you can dynamically allocate based on the length of the string from the first character after the '-' up until the first space if it exists, and if the pattern is a match. Obviously this eats up CPU time too. sscanf() is an easy solution as an alternative to parsing and pattern matching manually. |