Hi, I have an interesting regex puzzle I hope you might be able to help me with.
What I want to do is assign a 'score' to various strings, based on their prefix. So if a file starts with 'UKL' or 'USL', it receives a score of 10; if it starts with 'EUK' or 'EUS' it receives a score of 9, if...
Makes no difference, I'm afraid. I thought the non-greedy quantifier was only when using wild-card characters like . ? By restricting the regex to search for everything that isn't a closing angle bracket, I'm doing away with the need for the question mark.
Hi, I've been searching CPAN for a while now, but I can't find an easy way to convert a Unicode entity (eg л) to UTF-8. Any advice will be very gratefully received. Thanks!
Can't go into too much detail, but they're HTML tables that have been created manually for an application that runs under Mozilla. I didn't spec for id's when they were created, but now we need the id's in there. I just need a quick & dirty way of doing it, I don't really have the time to get...
Hi, I'm trying to add an id number to each cell in a bunch of HTML tables, so I'm using the code:
while ($tabdat =~ s/<td /<td id="$idnum" /g) {
$idnum++;
}
This just hangs in a loop, so how do I do this? Apologies if this is really simple, it's Friday afternoon and I've had quite a day...
Thanks - I thought of that, but the list is going to be very long - it's the contents of a dictionary, basically. This seems very inefficient to me, surely there's a better way?
Hi, I can't find a function that will return the position of a string within an array. For example, if the array is:
[aardvark, abacus, abandon, abate, abattoir...]
I want to search it for 'abate' and return position 3. What I want to do is search an alphabetically-sorted list and see which...
Won't that fail if the file has non-word characters (eg numbers or percent signs)? I would say:
$url =~ m|/([^/]*)$|;
#ie all the non-slash characters after the last slash up to the end of the string
$filename = $1;
Dom
...except 'some link', 'link name' and 'stuff' always going to be part of the string to replace? And is the ' or <a' alternative link always part of it? If so, I think the following:
s/<a href="([^"]*)"[^>]*>[^<]*<\/a> or <a href="([^"]*)"[^>]*>[^<]*<\/a><\/p><h2><br>/$1, $2/
should work.
Dom
to clarify, if I run the code on the following strings, one after another:
<tag>a tag</tag><tag>another tag</tag>
<tag>yet another tag</tag>
I get:
<tag id="1">a tag</tag><tag id="1">another tag</tag>
<tag id="2">yet another tag</tag>
ie it seems the substitution happens for all matches in...
Hi, I'm having trouble with this code:
while ($data =~ s/<tag>/<tag id="$id">/g) {
$id++;
}
the problem is that the updated $id doesn't get substituted in the loop, although the variable does get updated. I thought that so long as you don't use the o qualifier, the regex will recompile...
...someone out there can save me the bother of searching through the manuals. Is there any way of telling Perl not to treat reserved characters (+, * etc) as special when they occur in interpolateed variables? For example, I had an array of various codes, some of which began with a +, and I was...
but the data isn't in the tag itself, it's in the value of the tag, so if $word is the word to find, and $html the HTML string:
$html =~ s|<([^>]*)>[^<]*$word[^<]*</\1>||g;
should do it.
Domster
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.