Raised This Month: $ Target: $400
 0% 

regex issue


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HSFighter
Veteran Member
Join Date: Aug 2007
Location: Flensburg - Germany
Old 05-04-2012 , 11:30   regex issue
Reply With Quote #1

Hi all,

i try to extract a steamid between 2 nodes.
But i recive a "No match found!"

Here the example:

Data String:
Code:
Date: Thu, 02 May 2012 14:18:38 GMT
         Server: Apache
         Vary: Accept-Encoding
         Content-Length: 230
         Connection: close
         Content-Type: text/xml
         
         <?xml version='1.0' standalone='yes'?><headtag>
           <test>STEAM_0:1:101010101</test>
           <b>NO</b>
           <c>YES</c>
           <d>FINE</d>
           <e>DATA</e>
         </headtag>
Code:
PHP Code:
#include <sourcemod>
#include <regex>

stock GetXMLNodeData(const String:XML[], String:buffer[], maxlen)
{
    static 
Handle:re INVALID_HANDLE;
    if (
re == INVALID_HANDLE)
        
re CompileRegex("/<test>(.+)<\\/test>/");
        
    if (
MatchRegex(reXML) > 1)
        
GetRegexSubString(re1buffermaxlen);
    else
        
strcopy(buffermaxlen"No match found!");
}

// ============

    // Stuf to get "xmldata"....

    
decl String:info[256];
    
GetXMLNodeData(xmldatainfosizeof(info));
    
LogToGame ("Debug: %s",xmldata);
    
LogToGame ("-------------------------------------------");
    
LogToGame ("Debug: %s",info); 
Any Ideas whats wrong?
__________________



Sorry for my very bad english
Greetings HSFighter

Last edited by HSFighter; 05-04-2012 at 11:38.
HSFighter is offline
Send a message via ICQ to HSFighter
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 05-04-2012 , 11:47   Re: regex issue
Reply With Quote #2

Have a look at [EXTENSION] TinyXml Wrapper
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
HSFighter
Veteran Member
Join Date: Aug 2007
Location: Flensburg - Germany
Old 05-04-2012 , 11:59   Re: regex issue
Reply With Quote #3

Hi berni,

not possible with this extension to read directly from a string.

Quote:
Originally Posted by Thrawn2 View Post
you'll need to strip the header no matter what.

after that: currently (as i don't have a method implement to read the xml from a string) you'll need to write it to a file and load it from there
I do not want to write a xml file on the server first.
I need only the steamid from the string without an extension.
__________________



Sorry for my very bad english
Greetings HSFighter

Last edited by HSFighter; 05-04-2012 at 12:09.
HSFighter is offline
Send a message via ICQ to HSFighter
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 05-04-2012 , 17:17   Re: regex issue
Reply With Quote #4

I think it works without files too:

PHP Code:
native TinyXml_Parse(Handle:docString:xmldata[]); 
I'm gonna test your code on my server ;)
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 05-04-2012 , 17:23   Re: regex issue
Reply With Quote #5

ehhh

MatchRegex returns:
Number of substrings found or -1 on failure.

you are checking for > 1 ? that would only be true if it exists more than one time.

The compiler probably also puked at the if statements without { } brackets

Edit: you seem to be right with checking > 1, however the regex pattern didn't work.
I tested a bit around and this is working for me:

PHP Code:
CompileRegex("<test>(.+)</test>"); 
MatchRegex then returned 2 (somehow) and buffer contains the desired value: "STEAM_0:1:101010101"
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 05-04-2012 at 17:36.
berni is offline
HSFighter
Veteran Member
Join Date: Aug 2007
Location: Flensburg - Germany
Old 05-04-2012 , 18:04   Re: regex issue
Reply With Quote #6

Thank you berni.

The "> 1" was the first issue. But after the fix my check returns every times a "0".

I get it after some test's and help from Impact123

Here the full function (works fine):

PHP Code:
stock GetXMLNodeData(const String:XML[], const String:node[], String:buffer[], maxlen)
{
   
    
decl String:pattern[256];
    
Format(patternsizeof(pattern), "(<%s>)([A-Za-z0-9:_]+)(</%s>)"nodenode);
    static 
Handle:re INVALID_HANDLE;
    if (
re == INVALID_HANDLE)
    {
        
re CompileRegex(pattern);
    }

    if (
MatchRegex(reXML) >= 1)
        
GetRegexSubString(re2buffermaxlen);
    else
        
strcopy(buffermaxlen"No match found!");
}

//=============

    // data = XML String

    
decl String:steamid[256];
    
GetXMLNodeData(data"test"steamsizeof(steam)); 
Thank you all for your effort.
__________________



Sorry for my very bad english
Greetings HSFighter

Last edited by HSFighter; 05-04-2012 at 18:07.
HSFighter is offline
Send a message via ICQ to HSFighter
Reply



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

Forum Jump


All times are GMT -4. The time now is 20:04.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode