Hi, I have a string ($sentence) containing pattern in this format:
A~~~.*~A
Now I wanna extract all "A~~~.*~A" from the string, each time i find one match, I change the $_ to contain the rest of the string, then sub the string by s/$_// and assign to $remainPart, so that the $remainPart only store the portion before this "A~~~.*~A" pattern..
However, i have a problem here, i extract $_ from $sentence, but cannot use it to sub $remainPart(which is equal to $sentence originally). Wondering why. Any suggestion?
Here is the source code:
#! usr/bin/perl $sentence = " he PP study VB A~~~language~A NP and CC play VB A~~~game~A NP ." $_ = $sentence; while ($_ ne '') { if (m/A~~~(.*)~A/g) { # global match $remainPart = $sentence; ($_) = /(\G(.|\n)*)/g; # store rest of the string # (after pos) to $_ $remainPart =~ s/$_//; print "$remainPart\n"; } else { $_ = ''; } }
By right, first time the $_ will contain
" NP and CC play VB A~~~game~A NP ."
but as the $remainPart is printed out, it is still same as $sentence, which indicates the substitution is not successful.
In reply to Regexp Substitution Problem!! by bmal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |