in reply to substr function
This is most definitely an XY problem. Sounds like you want to do something like the following, but you haven't really said what you are trying to do.
# Tokenise my @tokens = $doc =~ /<[^>]*>|./sg; # Extract text my @text_tokens = grep /^<|<[0-9]+>/, @tokens; # Do stuff with @text_tokens # ... # Print resulting text print join('', @text_tokens);
or maybe
# Tokenise my @tokens = $doc =~ /<[^>]*>|./sg; # Extract text my $text = ''; for (@tokens) { if (/^<([0-9]+)>/) { $text .= chr($1); } elsif (/^[^<]/) { $text .= $1; } } # Do stuff with $text # ... # Print resulting text print join('', $text);
Or do you need to output back in the original format (e.g. with bold tags in)?
Update: Added second snippet.
|
|---|