AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   regexp_match problem (https://forums.alliedmods.net/showthread.php?t=160235)

der_tabak 06-26-2011 13:01

regexp_match problem
 
I have the following pattern:
Code:

"^"BANNED^" ^"is banned on ([^^:]*): (.*)^"$"
and I want to match for this lines:
Code:

"BANNED" "is banned on Betreutes Zocken: "idiot""
"BANNED" "is banned on Zechhalle Hamburg: VAC ban(s) on record"
"BANNED" "is banned on German Headquarter: Wallhack (D2AMX)"
"BANNED" "is banned on Bohramt: TA, FLAME, Gibt zu das er an hat..."
"BANNED" "is banned on Die wilden Siebziger: Import Bann.cfg"
"BANNED" "is banned on Psychiatrie: Autoban:  Other accounts VAC-Banned"
"BANNED" "is banned on Lost-Boy-Scouts: Autoban:  Other accounts VAC-Banned"

But I don't get any matches in AMX mod X, but the pattern from above ist working for me on regexpal.com
Code:

"BANNED" "is banned on ([^:]*): (.*)"$
I could and tried also to match with this pattern for example:
Code:

"^"BANNED^" ^"is banned on ([^^:]*): ([^^^"]*)^""
But the problem is, as you can see above the quotation marks can also occur in between the outside marks.

I'm also calling the regexp_match() function with the "m" flag.

FoxueR 06-26-2011 17:32

Re: regexp_match problem
 
In AMXX, ^ is the escape character. If you want to include it in a string, you have to use ^^, similar to how you would use \\ for \ in C.

der_tabak 06-26-2011 17:49

Re: regexp_match problem
 
Look at my first pattern, its already AMXX escaped, but it looks like the $ sign does not act like it should.

This is my unescaped regex pattern:
Code:

"BANNED" "is banned on ([^:]*): (.*)"$
It's working on regexpal.com properly with the lines in my first post.

AMXX escaped this looks like this:
Code:

"^"BANNED^" ^"is banned on ([^^:]*): (.*)^"$"
But I don't get any matches for lines like:
Code:

"BANNED" "is banned on Zechhalle Hamburg: VAC ban(s) on record"
"BANNED" "is banned on Betreutes Zocken: "idiot""


Exolent[jNr] 06-26-2011 18:43

Re: regexp_match problem
 
"BANNED" "is banned on ([^:]+): (.+)"

Works on all different test data you provided.

Code:

] regex_pattern ""BANNED" "is banned on ([^:]+): (.+)""
Pattern set to: "BANNED" "is banned on ([^:]+): (.+)"
] regex_test ""BANNED" "is banned on Betreutes Zocken: "idiot"""
3 matches
1. ""BANNED" "is banned on Betreutes Zocken: "idiot"""
2. "Betreutes Zocken"
3. ""idiot""
] regex_test ""BANNED" "is banned on Zechhalle Hamburg: VAC ban(s) on record""
3 matches
1. ""BANNED" "is banned on Zechhalle Hamburg: VAC ban(s) on record""
2. "Zechhalle Hamburg"
3. "VAC ban(s) on record"
] regex_test ""BANNED" "is banned on German Headquarter: Wallhack (D2AMX)""
3 matches
1. ""BANNED" "is banned on German Headquarter: Wallhack (D2AMX)""
2. "German Headquarter"
3. "Wallhack (D2AMX)"
] regex_test ""BANNED" "is banned on Bohramt: TA, FLAME, Gibt zu das er an hat...""
3 matches
1. ""BANNED" "is banned on Bohramt: TA, FLAME, Gibt zu das er an hat...""
2. "Bohramt"
3. "TA, FLAME, Gibt zu das er an hat..."
] regex_test ""BANNED" "is banned on Die wilden Siebziger: Import Bann.cfg""
3 matches
1. ""BANNED" "is banned on Die wilden Siebziger: Import Bann.cfg""
2. "Die wilden Siebziger"
3. "Import Bann.cfg"
] regex_test ""BANNED" "is banned on Psychiatrie: Autoban:  Other accounts VAC-Banned""
3 matches
1. ""BANNED" "is banned on Psychiatrie: Autoban:  Other accounts VAC-Banned""
2. "Psychiatrie"
3. "Autoban:  Other accounts VAC-Banned"
] regex_test ""BANNED" "is banned on Lost-Boy-Scouts: Autoban:  Other accounts VAC-Banned""
3 matches
1. ""BANNED" "is banned on Lost-Boy-Scouts: Autoban:  Other accounts VAC-Banned""
2. "Lost-Boy-Scouts"
3. "Autoban:  Other accounts VAC-Banned"


der_tabak 06-26-2011 19:37

Re: regexp_match problem
 
Thanks, I solved the problem now by a bit trial and error, but I have forgotten to mention that my string looks more like this:
Code:

"BANNED" "is banned on Betreutes Zocken: Verdacht auf Cheat/ Multiacc."\r
"BANNED" "is banned on Puppets: Wallhack"\r
"BANNED" "is banned on Zechhalle Hamburg: VAC ban(s) on record"\r

So now this pattern works for me to get the first match:
Code:

"^"BANNED^" ^"is banned on ([^^:]+): ([^^^r]+)^"^r"
But my final question is, is there a possibility to get all matches from the entire string at once, or do I need to split the string on \r, and then try to match for every line?

FoxueR 06-26-2011 19:47

Re: regexp_match problem
 
Use something like this:

PHP Code:

new numerror[128], Regex:regex
regex 
regex_matchinput_str"^"BANNED^" ^"is banned on ([^^:]+): ([^^^r]+)^"^r"numerrorcharsmaxerror ) ) 

new 
substr[64]
for ( new 
inumi++ )
{
    
regex_substrregexisubstrcharsmaxsubstr ) )

    
// do something
}

regex_freeregex 

Of course, you'll need to add error handling and such.

der_tabak 06-26-2011 19:48

Re: regexp_match problem
 
Yes, I'm using this method, but this extracts only the matches of the first line, and not all the matches in my string, which contains multiple occurences(lines) of this pattern.

FoxueR 06-26-2011 19:50

Re: regexp_match problem
 
You'll probably have to break it up.

der_tabak 06-26-2011 20:08

Re: regexp_match problem
 
Ok, thanks.

fysiks 06-27-2011 02:51

Re: regexp_match problem
 
It depends on how you get the data. If using file operations (fopen, fget, etc) then you would parse them line by line in the loop anyways and you do your regex there.


All times are GMT -4. The time now is 23:28.

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