I believe you can get the function to work expanding the regex a little bit.
$s = "***ab***c"; $s =~ s/\*([^\n])/\*\n\1/ for 1 .. 2; print $s;
Output was:
* * *ab***c
Since you know the state it's going to be after it's changed, you can include that in the regex. Hence *, not followed by \n will match, along with the for loop suggested earlier, gives you your count. Using \1 here just puts the next value (after the matched *) back into the string.
Update: markkawika's comment might be below threshold, so I'll add it here as well, since his regex is better than mine. Suggested regex: s/\*(?!\n)/*\n/
In reply to Re^3: how to search and replace the match with specific number of times in a string
by Verillion
in thread how to search and replace the match with specific number of times in a string
by loki
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |