my $e = '\\' # kind of escape char
my $s = '\''; # this is a string to use for splitting
if(string_contains_newlines()) {
$s .= "\n"; # ?? right so?
}
my $re = "(?
That is to say: when the string to split contains newlines (or --more precisely-- $/) I need to split the string according to a new regular expression that takes the former separator (stored in $s here) plus the newline character(s).
As you might guess, the above code doesn't work and I've run out of ideas what else to try.
Any hints or help appreciated.
Regards...
Stefan
you begin bashing the string with a +42 regexp of confusion
Re: Matching Newlines in RegExp
created: 2004-06-14 15:37:15
First off, sorry, I have no idea what you're trying to do, so I can offer no concrete help.
However, as nobody has answered this question in the more than six hours that have passed since it was posted, and as you have "run out of ideas", why not try [cpan://YAPE::Regex::Explain]?
Something like this:
use YAPE::Regex::Explain;
# Your code as posted
my $regex = YAPE::Regex::Explain->new ( qr/$split_re/ );
print $regex->explain;
dave
Re: Matching Newlines in RegExp
created: 2004-06-14 15:43:07
When you say "the above code doesn't work", I think you mean "I didn't get the result I expected".
So what result did you expect, and what result did you get?
Sometimes I find it usefult to make simple "Test::More" style tests when illustrating for others that something isn't working. This means that I have a complete code sample that isolates and reproduces the issue. It also makes it clearer what results I expected compared to those I actually got. Finally, I can keep the result asan automated test script to run later to verify the quality of my software.
I think with a clearer example, more suggestions will appear about how to fix or improve your code.
Re: Matching Newlines in RegExp
created: 2004-06-14 15:50:14
I agree with the prior replies... I'm not exactly sure what you are looking for... I tried out your code on a fairly simple example and it seems to work fine:
#!/usr/bin/perl -w
use strict;
my $e = '\\'; # kind of escape char
my $s = '\''; # this is a string to use for splitting
my $str = "this \n contains \\'\n new lines " .
"and single'\nquotes'\n more than\' once";
if( $str =~ m#$/# ) {
$s .= "$/"; # ?? right so?
}
my $re = qr/(?
gives the following output:
% ./test.pl
3
0: this
contains \'
new lines and single
1: quotes
2: more than' once
The string was split on '\n, but not \'\n, \n or '.
Re: Matching Newlines in RegExp
created: 2004-06-15 05:20:05
Fellow Monks,
thanks for you replies. I am well aware that I was in no state of mind to either hunt bugs or post questions.
When later I broke the problem at hand down to a small test programm I found that my first guess actually worked (that making me feel less stupid :-).
The real problem was another regexp from another module from a quite largy (self written) library. Anyway, today, with a fresh mind, I could solve this.
Again: thanks.
Regards...
Stefan
you begin bashing the string with a +42 regexp of confusion
perlmonks.org content © perlmonks.org and markjugg, Not_a_Number, orderthruchaos, stefan k
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03