Raised This Month: $32 Target: $400
 8% 

Can't compile regex expression.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
T1MOXA
Member
Join Date: Aug 2016
Old 07-18-2018 , 15:34   Can't compile regex expression.
Reply With Quote #1

Code:
#include <regex>
public void OnPluginStart() {
    PrintToServer("%i", CompileRegex("[\x{D800}-\x{DBFF}]", PCRE_CASELESS));
}
Return: 0

What am I doing wrong ?

UPD.
the same proplem with "[\\x{D800}-\\x{DBFF}]" expression.

Last edited by T1MOXA; 09-23-2018 at 01:41.
T1MOXA is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 07-18-2018 , 16:33   Re: Can't compile regex expression.
Reply With Quote #2

How about you, idk, use the error params...

PHP Code:
Regex CompileRegex(const char[] patternint flagschar[] errorint maxLenRegexErrorerrcode
Ill just add, that you should use SM 1.9 for those (since they were broken previously)

Last edited by Dr!fter; 07-18-2018 at 16:38.
Dr!fter is offline
T1MOXA
Member
Join Date: Aug 2016
Old 07-18-2018 , 16:47   Re: Can't compile regex expression.
Reply With Quote #3

Quote:
Originally Posted by Dr!fter View Post
How about you, idk, use the error params...

PHP Code:
Regex CompileRegex(const char[] patternint flagschar[] errorint maxLenRegexErrorerrcode
Ill just add, that you should use SM 1.9 for those (since they were broken previously)
Thanks...

PHP Code:
#include <regex>

public void OnPluginStart() {
    
char sError[128];
    
RegexError rError;
    
Handle hExpression CompileRegex("[\\x{D800}-\\x{DBFF}]"PCRE_UCPsErrorsizeof(sError), rError);
    
PrintToServer("Regex: %i | Error: %s | RegexError: %i"hExpressionsErrorrError);

Regex: 0 | Error: this version of PCRE is not compiled with Unicode property support | RegexError: 16

sm exts list
Regex (1.9.0.6241): Provides regex natives for plugins

With PCRE_CASELESS flag:
Regex: 0 | Error: character value in \x{...} sequence is too large | RegexError: 3

Last edited by T1MOXA; 07-18-2018 at 16:54.
T1MOXA is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 07-18-2018 , 18:22   Re: Can't compile regex expression.
Reply With Quote #4

The root of your problem seems to be:

Quote:
Constraints on character values

Characters that are specified using octal or hexadecimal numbers are limited to certain values, as follows:

8-bit non-UTF mode less than 0x100
8-bit UTF-8 mode less than 0x10ffff and a valid codepoint
16-bit non-UTF mode less than 0x10000
16-bit UTF-16 mode less than 0x10ffff and a valid codepoint
32-bit non-UTF mode less than 0x100000000
32-bit UTF-32 mode less than 0x10ffff and a valid codepoint

Invalid Unicode codepoints are the range 0xd800 to 0xdfff (the so-called "surrogate" codepoints), and 0xffef.
https://www.pcre.org/original/doc/html/pcrepattern.html
__________________
asherkin is offline
T1MOXA
Member
Join Date: Aug 2016
Old 07-18-2018 , 20:44   Re: Can't compile regex expression.
Reply With Quote #5

Thanks, but I'm not sure what it gives me...
By the way, here this expression works as it should.
From your answer I understood that most likely to do what I want using regex is not possible ?
Perhaps there is an alternative option as find emoticons in the text and remove their ?

Last edited by T1MOXA; 07-18-2018 at 20:46.
T1MOXA is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 07-19-2018 , 11:04   Re: Can't compile regex expression.
Reply With Quote #6

Regex re = new Regex("[\\pSo]", PCRE_UTF8, error, sizeof(error), iError);

Seems to work here is a list of what it captures.
https://www.fileformat.info/info/uni...ry/So/list.htm
Dr!fter is offline
T1MOXA
Member
Join Date: Aug 2016
Old 07-20-2018 , 20:36   Re: Can't compile regex expression.
Reply With Quote #7

Unfortunately, this rule removes too many characters.
I am writing this regular expression to remove those characters from nicknames which do not properly send to the MySQL server.

To avoid such errors:
Incorrect string value: '\xF0\x9F\x98\x88 6...' for column 'name' at row 1

Last edited by T1MOXA; 07-20-2018 at 20:38.
T1MOXA is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 07-20-2018 , 20:40   Re: Can't compile regex expression.
Reply With Quote #8

You should really consider switching to the utf8mb4 charset.
__________________
asherkin is offline
T1MOXA
Member
Join Date: Aug 2016
Old 07-20-2018 , 22:11   Re: Can't compile regex expression.
Reply With Quote #9

Then I'll have to rewrite all plugins and web interfaces to a different encoding...
And in general it is interesting why this rule does not work in sourcemod but it works on the regex101.

Last edited by T1MOXA; 07-20-2018 at 22:12.
T1MOXA is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 07-21-2018 , 05:38   Re: Can't compile regex expression.
Reply With Quote #10

No you won’t, the input/output is still UTF-8, it just allows characters outside of the BMP to be stored.
__________________
asherkin is offline
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

Forum Jump


All times are GMT -4. The time now is 00:54.


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