DW RegExp broken, or me?

Ask a Question related to Macromedia Exchange Dreamweaver Extensions, Design and Development.

  1. #1

    Default DW RegExp broken, or me?

    If I have the following string:

    theText = "http://www.google.com/image.gif"

    and I apply this regular expression to it in DW:

    theText = theText.replace(/\.(.*)$/, "$1");

    I get the whole string. It seems to me that it should only return "gif".
    The parenthesis is between an end-of-line anchor and an escaped dot.
    That should mean that $1 is only the text between the end of the line
    and the last dot.

    Am I getting too sleepy?

    --
    Jerry Baker

    Automatic ALT text on all images
    HTML and XHTML doctype switching with a mouse click
    "Insert Image+" and "Insert (X)HTML Doctypes" Extensions
    [url]http://www.macromedia.com/cfusion/exchange/index.cfm?view=sn103&authorid=21726084[/url]
    Jerry Baker Guest

  2. Similar Questions and Discussions

    1. regexp help
      sjaak wrote at Thu, 26 Jun 2003 12:35:08 +0200: Simple way: s/(\.html?">)(</a>)/$1route$2/g; If you do a lot of such stuff, a HTML parser...
    2. regexp help please!
      I'm writing a PHP script inspired by smartypants and textile (but for PHP), which among other things does smart quoting. However, I want to avoid...
    3. i need a regexp
      Hello, That's easy: $s = array ( "<br />\n\r<br />", "<br />\n<br />", "<br />\r<br />", "<br />\n\n\n\n\n\n<br />" ); foreach($s as $i) {
    4. regexp
      Anton Arhipov wrote: You mean If you find any upper case word within quotes remove quotes right ? $str = 'abc "BLAH" aaa "eef" '; print...
    5. regexp help...
      Hi all, I have a string that for all practical purposes should probably be a list (array). I need one line from the string and need to send the...
  3. #2

    Default Re: DW RegExp broken, or me?

    On 18 Nov 2005 in macromedia.exchange.extensions.dreamweaver, Jerry
    Baker wrote:
    > If I have the following string:
    >
    > theText = "http://www.google.com/image.gif"
    >
    > and I apply this regular expression to it in DW:
    >
    > theText = theText.replace(/\.(.*)$/, "$1");
    >
    > I get the whole string. It seems to me that it should only return
    > "gif". The parenthesis is between an end-of-line anchor and an
    > escaped dot. That should mean that $1 is only the text between the
    > end of the line and the last dot.
    >
    > Am I getting too sleepy?
    I just ran it through the regex tester in XNews
    ([url]http://xnews.newsguy.com[/url]). You've got 3 dots (periods, 0x2e) in
    theText, and your expression matches the first dot, so the expression
    returns "google.com/image.gif" Try looking for the first dot after the
    slash: /\/.*\.(.*)$/

    --
    Joe Makowiec
    [url]http://makowiec.net/[/url]
    Email: [url]http://makowiec.net/email.php[/url]
    Joe Makowiec Guest

  4. #3

    Default Re: DW RegExp broken, or me?

    Joe Makowiec wrote:
    > I just ran it through the regex tester in XNews
    > ([url]http://xnews.newsguy.com[/url]). You've got 3 dots (periods, 0x2e) in
    > theText, and your expression matches the first dot, so the expression
    > returns "google.com/image.gif" Try looking for the first dot after the
    > slash: /\/.*\.(.*)$/
    Then DW gives me "http:gif"

    --
    Jerry Baker

    Automatic ALT text on all images
    HTML and XHTML doctype switching with a mouse click
    "Insert Image+" and "Insert (X)HTML Doctypes" Extensions
    [url]http://www.macromedia.com/cfusion/exchange/index.cfm?view=sn103&authorid=21726084[/url]
    Jerry Baker Guest

  5. #4

    Default Re: DW RegExp broken, or me?

    On 18 Nov 2005 in macromedia.exchange.extensions.dreamweaver, Jerry
    Baker wrote:
    > Joe Makowiec wrote:
    >> I just ran it through the regex tester in XNews
    >> ([url]http://xnews.newsguy.com[/url]). You've got 3 dots (periods, 0x2e) in
    >> theText, and your expression matches the first dot, so the
    >> expression returns "google.com/image.gif" Try looking for the
    >> first dot after the slash: /\/.*\.(.*)$/
    >
    > Then DW gives me "http:gif"
    Well, think this through. What precedes any of what you actually want?
    If they all have [url]http://,[/url] then include that in the regex:

    http:\/\/

    If they aren't all preceded by [url]http://,[/url] then it would be (http:\/\/)?
    (the ? means "0 or one of what's in the preceding ()"); note that this
    would change your reference from $1 to $2.

    Then you can have anything, up to the next slash:

    ..*\/

    Then anything:

    ..*

    Then the dot preceding the extension:

    \.

    then the extension at the end of the line:
    (.*)$

    and the whole regex is:

    /http:\/\/.*\/.*\.(.*)$/

    --
    Joe Makowiec
    [url]http://makowiec.net/[/url]
    Email: [url]http://makowiec.net/email.php[/url]
    Joe Makowiec Guest

  6. #5

    Default Re: DW RegExp broken, or me?

    Joe Makowiec wrote:
    > and the whole regex is:
    >
    > /http:\/\/.*\/.*\.(.*)$/
    Thanks for the assistance. The regex that finally worked is:

    ..match(/\.[^\/]*$/)

    --
    Jerry Baker

    Automatic ALT text on all images
    HTML and XHTML doctype switching with a mouse click
    "Insert Image+" and "Insert (X)HTML Doctypes" Extensions
    [url]http://www.macromedia.com/cfusion/exchange/index.cfm?view=sn103&authorid=21726084[/url]
    Jerry Baker Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139