Peter Hickman said:
tor said:
Hello
I want to put a new line after each ', but not after ?'.
If someone are familiare with edifact they understand.
How about this?
$a = "AAA+Tim?'s'BBB+123'";
print "$a\n";
$a =~ s/([^\?]')/$1\n/g;
Question marks are not special in character classes. No need for a
backslash there.
print "$a\n";
The ([^\?]') says match and capture any character other than a ? that is
followed by a '
The $1\n says replace this with whatever you captured plus a newline
I'm not familiar with EDIFACT, so this may not apply. However, if there
is a possibility that a ' could be the first (or only) character in the
string, and you need to insert a newline after it, this will not work.
The [^?] requires an actual character.
To match just "an apostrophe not preceded by a question mark" (rather
than "anything that's not a question mark, followed by an apostrophe"),
you need to use negative lookbehind assertions:
s/(?<!\?)'/'\n/;
Paul Lalli