Aug-26-2020, 06:26 AM
@bowlofred
With regex, at least the PCRE I am used to \. is always a period, and . means 'any character'.
In python it seems r'.' means any character.
Lets do regex strings:
a = "fee...fi....fo.....fum"
b = re.sub("\.","\-",a)
-> fee\-\-\-fi\-\-\-\- (&etc)
and I would need to give a bare "_" for it to work as
-> fee___fi____fo______fum
b = re.sub(r'.',r'_',a)
-> _____________________
The entire string is wiped out.
r'.' is NOT a raw character, at least with the re class.
And escaping '-' (\-)is not working as expected in regex mode.
In Perl I would typically use something like:
x =~ s/^.*(fee).+(fi).+(fo).+(fum).*$/$1,$3,$2,$4/ -> ...fee...fo...fi...fum
I do see that the basic syntax seems OK at:
https://regex101.com/
Though re apparently uses \1 instead of the ancient \$1 format.
I see there is a python-pcre module, but it seems even more obfuscated than a Perl poem.
I started with raw mode, and switched to regex ("foo") mode when I ran into problems.
Not a problem really, all languages have their peculiarities.
By space problem I mean (dot)(space)(backslach). If it write it as is Mybb will kill the space. Cocatenating '.'+'filename' was giving me that space which was screwing up the matching. Omitting the step wound up fixing the problem. os.path apparently subblied its own . for the var.
With regex, at least the PCRE I am used to \. is always a period, and . means 'any character'.
In python it seems r'.' means any character.
Lets do regex strings:
a = "fee...fi....fo.....fum"
b = re.sub("\.","\-",a)
-> fee\-\-\-fi\-\-\-\- (&etc)
and I would need to give a bare "_" for it to work as
-> fee___fi____fo______fum
b = re.sub(r'.',r'_',a)
-> _____________________
The entire string is wiped out.
r'.' is NOT a raw character, at least with the re class.
And escaping '-' (\-)is not working as expected in regex mode.
In Perl I would typically use something like:
x =~ s/^.*(fee).+(fi).+(fo).+(fum).*$/$1,$3,$2,$4/ -> ...fee...fo...fi...fum
I do see that the basic syntax seems OK at:
https://regex101.com/
Though re apparently uses \1 instead of the ancient \$1 format.
I see there is a python-pcre module, but it seems even more obfuscated than a Perl poem.
I started with raw mode, and switched to regex ("foo") mode when I ran into problems.
Not a problem really, all languages have their peculiarities.
By space problem I mean (dot)(space)(backslach). If it write it as is Mybb will kill the space. Cocatenating '.'+'filename' was giving me that space which was screwing up the matching. Omitting the step wound up fixing the problem. os.path apparently subblied its own . for the var.