Now I just ran into another problem. Some of my strings contain backslashes. This seems to break everything...
If I use:
$string = 'Param1(TYPE,\abc\),Param2(TYPE,\abc\)';
things break :-(
I tried using double quotation marks instead, but of course that makes it interpret the backslashes differently/incorrectly.
Any ideas?
Thanks again.
Emma | [reply] [d/l] |
You are (semi)hosed, as far as extract_bracketed() is concerned. The problem with backslashes is that they're used to escape things. That lets you represent non-printable characters, such as \n or \t, in a printable manner, as well as allowing one to say things like:
my $s = "This string \" has an escaped quote";
If you then print $s, you get:
This string " has an escaped quote
If you are trying to match balanced quotes on that string, you need to skip over the escaped quote inside. This is one of the reasons responders to your original post suggested that parsing balanced thingies is difficult to do with regular expressions.
Looking at the source code in Text::Balanced, there is, indeed, a line that always eats the next character following a backslash:
next if $$textref =~ m/\G\\./gcs;
Your sample suggests that the input is using backslashes as some form of quoting operator, rather than an escape character. If that's a true assumption, then you might try normalizing your input to change the backslashes into something else (and then back again after you're done parsing):
For example:
$string = 'Param1(TYPE,\abc\),Param2(TYPE,\abc\)';
$string =~ tr{\\}{:};
Cheers,
| [reply] [d/l] [select] |
Thanks a million! Got it to work by replacing the backslashes by "::". :-)
Emma
| [reply] |
Aha. Wonderful. That works. Thanks!!!!!
Though I would have thought '.*?' would try to match a pattern as short as possible (because of the "?") and thus not include the parentheses? Anyway, I guess I still don't fully understand the regex stuff.. but I'm glad my code now works. :-)
Thanks again!
Emma
| [reply] |