Re^2: Regex with Backslashesby anita2R (Scribe)
|on May 17, 2020 at 18:44 UTC||Need Help??|
Thanks for your reply. The data that is received consists of a single quoted string of characters. This '1,//Text//Text,C,150' is 22 characters long, as shown when I use print length($cmdValues) . "\n";, so double backslash is really two characters in the data I am processing. Later in the script if a backslash is followed by another backslash it is replaced with a single character that is displayed on an lcd screen.
The hex code was meant to mean two hex characters, rather than literally two characters, in the form 0xFF, sorry for any confusion.
I will use qr for all further work, as suggested.
, no, the input data is'1,Something\,\\text\\text\\0x2B\\,X,99'
The expected outcome is an array containing the following:
The string should be split on every comma and every comma preceded by two backslash characters, but not on a comma preceded by a single backslash.
I have looked at the quote-like operators and had already been through an interesting discussion starting at Ways of quoting
..."in my $regex = '(?<!\\\),';, the string actually only contains two backslashes because '\\' becomes \ but '\)' remains as \)" ... Using Data::Dumper, I can now see (I think) why my original regex worked:
The string I was splitting looks like thismy $text = '1,This\, is a problem->\\,B,99';
but when printed with Dumper it looks like this$VAR1 = "1,This\\, is a problem->\\,B,99";
So both '\,' and '\\,' appear the same during processing. Is there a way I can stop '\,' being processed as '\\,'.
I may have to go down the route of a custom parser as you have suggested