SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 28/07/2018, 03:32 AM   #1
Dayrion
High-roller
 
Dayrion's Avatar
 
Join Date: Jan 2016
Location: France
Posts: 1,915
Reputation: 258
Default REGEX - YourShadow's plugin

Hello.
I'm learning a bit REGEX and I tried to use the regular expression I made on pawn by using Pawn.Regex plugin (made by YourShadow - http://forum.sa-mp.com/showthread.php?t=609570) but nothing works.

There is my expression : https://regex101.com/r/FT3L4d/1/
Here is my code:
PHP Code:
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(exprregmatch)) 
    {
        
Match_GetGroup(match1_result_result_length);
        
Match_Free(match);
    }

    
printf("- '%s' - %i"_result_result_length);
    for(new 
i!= _result_lengthi++)
        
printf("- '%s'"_result[i]);

    
Regex_Delete(reg);

Maybe I misunderstood the usage of natives functions?
__________________
actor_plus - v5.0.2
I'm a goner, somebody catch my breath,
I'm a goner, somebody catch my breath
Dayrion is offline   Reply With Quote
Old 28/07/2018, 12:27 PM   #2
BlackBank
Gangsta
 
Join Date: Dec 2010
Location: The Netherlands
Posts: 522
Reputation: 437
Default Re: REGEX - YourShadow's plugin

Uhm if i put your regex into a regex tester, it doesn't fetch anything., as you can see here: https://regexr.com/3t4hc
BlackBank is offline   Reply With Quote
Old 28/07/2018, 02:55 PM   #3
Dayrion
High-roller
 
Dayrion's Avatar
 
Join Date: Jan 2016
Location: France
Posts: 1,915
Reputation: 258
Default Re: REGEX - YourShadow's plugin

Quote:
Originally Posted by BlackBank View Post
Uhm if i put your regex into a regex tester, it doesn't fetch anything., as you can see here: https://regexr.com/3t4hc
You need to use
Code:
[A-Z0-9_]*-?\d+(.\d+)?
and not
Code:
[A-Z0-9_]*-?\\d+(.\\d+)?
The second one is made for pawn because of escaped characters in string.

Quote:
Originally Posted by [HLF]Southclaw View Post
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.
Regex101 is actually highlighting what I want to retrieve. I guess it's doing what I want it do!
Yep, you are right. Escaped characters are needed for pawn that's why I linked a online regex tester to show you the expression without any escaped characters.

I just wanted to get the object's name, positions, rotations plus the interior. Nothing more! I don't even map, I just took the line of code from a random map found on Internet. I just wanted to train with regular expressions and do something other than detecting a RP name, a phone number or an email address. If you think that dumb to train on pawn, any advices is appreciated.

Thanks for your detailed message.
__________________
actor_plus - v5.0.2
I'm a goner, somebody catch my breath,
I'm a goner, somebody catch my breath
Dayrion is offline   Reply With Quote
Old 29/07/2018, 10:02 AM   #4
Dayrion
High-roller
 
Dayrion's Avatar
 
Join Date: Jan 2016
Location: France
Posts: 1,915
Reputation: 258
Default Re: REGEX - YourShadow's plugin

Quote:
Originally Posted by ****** View Post
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).
I'm catching the object's name and some coordinates. Using only "\d+" doesn't take in count negative values and there is no way to know numer's type (float, int, ..).
__________________
actor_plus - v5.0.2
I'm a goner, somebody catch my breath,
I'm a goner, somebody catch my breath
Dayrion is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyone into RegEx? Sew_Sumi Everything and Nothing 22 19/06/2017 02:32 AM
plugin regex wont load elhanan Server Support 5 01/03/2017 07:12 PM
[Plugin] Regular Expressions Plugin v0.2 (RegEx) Koala818 Plugin Development 22 09/09/2016 07:36 AM
RegEx plugin fails to load Moron Scripting Help 12 04/04/2016 07:30 PM
Regex plugin needed!? Djane Scripting Help 7 13/12/2013 10:00 AM


All times are GMT. The time now is 11:50 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.