main()
{
new
_result[500],
_result_length,
expr[] = "object CJ_BIG_SKIP1 (1)\" doublesided=\"false\" model=\"1365\" interior=\"0\" dimension=\"0\" posX=\"-2681.3000488281\" posY=\"865.29998779297\" posZ=\"76.400001525879\" rotX=\"0\" rotY=\"0\" rotZ=\"0\"";
new Regex:reg = Regex_New("[A-Z0-9_]*-?\\d+(.\\d+)?"),
RegexMatch:match;
if (Regex_Match(expr, reg, match))
{
Match_GetGroup(match, 1, _result, _result_length);
Match_Free(match);
}
printf("- '%s' - %i", _result, _result_length);
for(new i; i != _result_length; i++)
printf("- '%s'", _result[i]);
Regex_Delete(reg);
}
Uhm if i put your regex into a regex tester, it doesn't fetch anything., as you can see here: https://regexr.com/3t4hc
|
[A-Z0-9_]*-?\d+(.\d+)?
[A-Z0-9_]*-?\\d+(.\\d+)?
The reason regex101 is highlighting your values is because your expression is so generic that it's matching almost anything. Another thing is, don't include the escape characters in your test data. Your string in Pawn requires `\"` to simple insert `"` into the string literal. When you read the string as data the `\` character will not be there.
The data you've supplied will need a much more complex regular expression to parse. You should move left to right matching what you need and adding to it. I've gotten you started: ^\"([a-zA-Z() 0-9_-]+)\" doublesided=\"(\w+)\" model=\"(\w+)\" But there's a bigger problem here: You're using the wrong tool for the job. This is not a task for regular expressions. I'm guessing you're parsing MTA's map editor output? That output is XML - a very standardised format that probably has more parsers than AFK systems on this forum! IIRC ****** wrote an XML parser, Zeex has done and a few others. XML is pretty heavy to parse so I'd advise using a plugin if speed is a problem. If you're doing this on server load, you probably don't need to worry. And finally, if you're actually just converting the code yourself - Pawn is absolutely the wrong tool for the job! You'll be surprised how fast you can accomplish things like text conversion and menial tasks like this in a language like Python, JavaScript, Ruby, Perl or even Bash. |
You have so many *s and ?s in there that basically all of the expression can be ignored:
"[A-Z0-9_]*-?\\d+(.\\d+)?" Basically becomes: "\\d+" I.e. will match (but not capture) any numbers anywhere (even the (1) near the start). |