Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) 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.

As to

"1,Something\\,\\\\text\\\\text\\0x2B\\\\,X,99"

, no, the input data is

'1,Something\,\\text\\text\\0x2B\\,X,99'

The expected outcome is an array containing the following:

1 Something\,\\text\\text\\0x2B\\ X 99

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 this

my $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


In reply to Re^2: Regex with Backslashes by anita2R
in thread Regex with Backslashes by anita2R

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-24 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found