Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. JavaScript

JavaScript

Scheduled Pinned Locked Moved The Lounge
javascriptquestion
12 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Am I the only person who, upon viewing the syntax for regular expressions in JavaScript, thought to himself, WTE? /[wte]/g :wtf:

    E Offline
    E Offline
    Eytukan
    wrote on last edited by
    #3

    For me it still applies if you remove the "JavaScript" from there.

    Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.

    L 1 Reply Last reply
    0
    • N Nagy Vilmos

      No, you are not the first and you will not be the last. To the best of my knowledge since release only 4 people have thought "wow, that's well designed".

      Reality is an illusion caused by a lack of alcohol "Nagy, you have won the internets." - Keith Barrow

      D Offline
      D Offline
      Dan Neely
      wrote on last edited by
      #4

      Nagy Vilmos wrote:

      To the best of my knowledge since release only 4 people have thought "wow, that's well designed".

      ... and all four of them have previously tried to parse html using regexes.

      Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

      1 Reply Last reply
      0
      • E Eytukan

        For me it still applies if you remove the "JavaScript" from there.

        Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #5

        Really? What language? For me the syntax of

        string.replace(/[wte]/g, string)

        was really bizarre. Placing the regular expression into forward slashes is something I'd never guess - and placing a modifier on the end was even stranger. Coming from a C#/VB background I would have expected quotes around the regular expression and the modifiers to be a 3rd parameter.

        E W 2 Replies Last reply
        0
        • L Lost User

          Am I the only person who, upon viewing the syntax for regular expressions in JavaScript, thought to himself, WTE? /[wte]/g :wtf:

          B Offline
          B Offline
          BobJanova
          wrote on last edited by
          #6

          No, I definitely WTEd at that when I discovered what you have to do. Actually though it's better than Java where it's a string so you have to double escape everything, it's just a bit weird.

          1 Reply Last reply
          0
          • L Lost User

            Am I the only person who, upon viewing the syntax for regular expressions in JavaScript, thought to himself, WTE? /[wte]/g :wtf:

            L Offline
            L Offline
            lewax00
            wrote on last edited by
            #7

            MehGerbil wrote:

            Am I the only person who, upon viewing the syntax for regular expressions in JavaScript, thought to himself, WTE?

            ;P But no, because I've seen that syntax before, in some Linux shell programs, and IIRC Perl uses it as well.

            1 Reply Last reply
            0
            • L Lost User

              Really? What language? For me the syntax of

              string.replace(/[wte]/g, string)

              was really bizarre. Placing the regular expression into forward slashes is something I'd never guess - and placing a modifier on the end was even stranger. Coming from a C#/VB background I would have expected quotes around the regular expression and the modifiers to be a 3rd parameter.

              E Offline
              E Offline
              Eytukan
              wrote on last edited by
              #8

              No I meant, the RegEx when it gets complex, it gets ugly naturally in any language I guess. Or I haven't spent much time on it yet ;)

              Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.

              1 Reply Last reply
              0
              • L Lost User

                Am I the only person who, upon viewing the syntax for regular expressions in JavaScript, thought to himself, WTE? /[wte]/g :wtf:

                A Offline
                A Offline
                AspDotNetDev
                wrote on last edited by
                #9

                Yeah, regex literals are strange in JavaScript, but to be fair I don't know of any other language with regex literals. JavaScript does also have a sinsible way to create a regex variable:

                var reggy = new RegExp("someregex", "options");

                Thou mewling ill-breeding pignut!

                W 1 Reply Last reply
                0
                • L Lost User

                  Really? What language? For me the syntax of

                  string.replace(/[wte]/g, string)

                  was really bizarre. Placing the regular expression into forward slashes is something I'd never guess - and placing a modifier on the end was even stranger. Coming from a C#/VB background I would have expected quotes around the regular expression and the modifiers to be a 3rd parameter.

                  W Offline
                  W Offline
                  w peuker
                  wrote on last edited by
                  #10

                  MehGerbil wrote:

                  Placing the regular expression into forward slashes is something I'd never guess - and placing a modifier on the end was even stranger. Coming from a C#/VB background I would have expected quotes around the regular expression and the modifiers to be a 3rd parameter.

                  Coming from a Perl background I found it surprisingly clear ;)

                  H 1 Reply Last reply
                  0
                  • A AspDotNetDev

                    Yeah, regex literals are strange in JavaScript, but to be fair I don't know of any other language with regex literals. JavaScript does also have a sinsible way to create a regex variable:

                    var reggy = new RegExp("someregex", "options");

                    Thou mewling ill-breeding pignut!

                    W Offline
                    W Offline
                    w peuker
                    wrote on last edited by
                    #11

                    AspDotNetDev wrote:

                    JavaScript does also have a sinsible way to create a regex variable:

                    var reggy = new RegExp("someregex", "options");

                    As for JavaScript, just keep in mind that the literal form

                    /regex/

                    is compiled once (when the script is loaded), whereas the explicit constructor call

                    new RegExp(pattern, options)

                    is compiled every time it's passed. see JavaScript RegExp Object... Regex is more enjoyable if you (can!) use(=write) it when needed. I have never regretted to have learned. (syntax isn't a big challenge any more)

                    1 Reply Last reply
                    0
                    • W w peuker

                      MehGerbil wrote:

                      Placing the regular expression into forward slashes is something I'd never guess - and placing a modifier on the end was even stranger. Coming from a C#/VB background I would have expected quotes around the regular expression and the modifiers to be a 3rd parameter.

                      Coming from a Perl background I found it surprisingly clear ;)

                      H Offline
                      H Offline
                      Herbie Mountjoy
                      wrote on last edited by
                      #12

                      PERL? Don't get me started...

                      I may not last forever but the mess I leave behind certainly will.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups