Hello there. I would like to ask help in selecting and formatting the first word of every line of an MS Word Document. What I planned to do is to first save the file as an HTML document, then use Perl to select the first word of every line and place <B> </B> tag-pair around it, then copy and paste the correctly-formatted view from my web browser back into MS Word.
A portion of the html-converted document can be downloaded from below.
Sample Document
I've been trying to make a perl script that looks for a pattern starting with <P> tag followed by HTML tags, if any, then a non-HTML tag text sequence. If the pattern was found, it'll look for a white-space character which is not within an HTML tag (i.e. <>) delimiters. The non-HTML tag character sequence until the white-space character should be enclosed in <B> and <</B> tags
I've made a code for this, but it isn't completely working. Hope someone helps and thanks in advance.
Here's my code
while(<>){
chomp;
$line = $_;
$line =~ s/(<P[^<]*>)( |<[^<]*>)*(\s*)([^\s<>]+)([^\s]|<[^<]*>)*(\
+s)(.*?<\/P[^<]*>)/$1 $2 $3 <B>$4 <\/B> $5 $6 $7/g;
print "$line\n";
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.