This should be a relatively simple question for the regex-minded. I have a lot of learning to do still. I have a document that I am parsing and I will have the people who write the documents put in a pseudo-XML tag if they want a blank page, like so:
<blank title="Title of My Page">
However, right now it only works if there are no spaces in the attribute title's value. So, TitleofMyPage would work with the following code:
#text is put in an array called page_text
foreach my $new_line(@page_text) {
#put each line into another array
my @blankPages = ($new_line =~ m/<blank[^>]+?title\s*=\s*["']?
+([^'" >]+?)[ '"]?>/sig);
foreach my $blankTitle(@blankPages) {
print "$blankTitle is the title\n";
#do some logic to add a blank page with that title
}
}
Of course I want it so I can put spaces in there. I was also wondering if it would be difficult to allow " and ' marks in there, because those throw it off too.
The last thing I couldn't figure out too was how to make an if statement that would fail if it did find that, because of course I don't want my text to include the xml tag. The following seems to not work, even when I try to take out the parentheses that grab the text I want (refer to the regex in code above):
if ($new_line =! m/sameregexasabove?/sig) {
#don't write a new line with the xml tag, but any other text is
+ okay
}
Your help would be much appreciated!
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.