in reply to Simple regex question
#!/usr/bin/perl use strict; use warnings; my $test_string = "foo l?est sé?jou ? foo "; $test_string =~ s/(?<!\s)\?(?!\s)/'/sig; print "$test_string\n";
The expression will fail when the character before ((?<!...)) the question mark is white space and when the character after ((?!...)) the question mark is white space. This will substitute if there is a leading or trailing question mark. These are zero-width assertions, so you don't have to worry about capturing. See perlre for details.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simple regex question
by ultranerds (Hermit) on Sep 15, 2010 at 14:48 UTC |