Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search results for query: *

  1. domster

    Regex to assign score?

    OP here - no, the data really is that simple, so I'm going to go off and try some of these great suggestions. Thanks all!
  2. domster

    Regex to assign score?

    Great stuff, guys, thanks! Just one problem with brigmar's - it's not necessarily the first three characters!
  3. domster

    Regex to assign score?

    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...
  4. domster

    $1 not set by regexp in loop

    It worked for me up to a point in the file, then stopped working - couldn't see anything in the file that would break it. I've got around it now by changing the s/// to a m// and removing the tag with with substr: foreach $line (@lines) { $line =~ s|^\s+||; print RPT "$line\n"; $bold = 0...
  5. domster

    $1 not set by regexp in loop

    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.
  6. domster

    $1 not set by regexp in loop

    I have a rough HTML file (from Word 98) that I'm trying to convert into XML. I've split it into lines on </P> tags, then I'm taking each line in turn, stripping off the tags at the start, then setting a variable $italic if a <I> or </I> tag is found, so: foreach $line (@lines) { $line =~...
  7. domster

    Unicode entity conversion

    Thanks, that's a really useful page - all it needed was the binmode statement from what I was already doing.
  8. domster

    Unicode entity conversion

    Hi, I've been searching CPAN for a while now, but I can't find an easy way to convert a Unicode entity (eg &#x043B;) to UTF-8. Any advice will be very gratefully received. Thanks!
  9. domster

    Updating a variable within a s///g

    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...
  10. domster

    Updating a variable within a s///g

    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...
  11. domster

    Position of string within array?

    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?
  12. domster

    Position of string within array?

    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...
  13. domster

    Regular expression help

    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
  14. domster

    regular expression help

    Is everything 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...
  15. domster

    Interpolating variables in a loop

    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...
  16. domster

    Interpolating variables in a loop

    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...
  17. domster

    regex special chars in interpolated variables

    \Q and \E - of course, silly me! Thanks both for the very fast response. Dom
  18. domster

    regex special chars in interpolated variables

    Hi, I'm hoping 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...
  19. domster

    RegExp to remove entire HTML tag

    True, I was assuming no intervening embedded tags. If there may be any, swap the [^<]*s with .*?s . Dom
  20. domster

    RegExp to remove entire HTML tag

    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

Part and Inventory Search

Back
Top