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. Web Development
  3. ASP.NET
  4. javascript regular expression

javascript regular expression

Scheduled Pinned Locked Moved ASP.NET
javascriptregexhelpquestion
4 Posts 2 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.
  • N Offline
    N Offline
    nesfrank
    wrote on last edited by
    #1

    I have this reg expression on javascript that checks for poboxes. how can I chnage it to map only for starting string and not anyqwhere on the string b/c if address is seAPOrt then it treats as a po box: var poboxPattern = new RegExp("(APO|A\.P\.O\.|A P O|FPO|F\.P\.O\.|F P O|POB|P\.O\.B\.|POBOX|P\.O\.BOX|PO BOX|P O BOX|P\.O\. BOX|POST OFFICE)"); Please help

    G 1 Reply Last reply
    0
    • N nesfrank

      I have this reg expression on javascript that checks for poboxes. how can I chnage it to map only for starting string and not anyqwhere on the string b/c if address is seAPOrt then it treats as a po box: var poboxPattern = new RegExp("(APO|A\.P\.O\.|A P O|FPO|F\.P\.O\.|F P O|POB|P\.O\.B\.|POBOX|P\.O\.BOX|PO BOX|P O BOX|P\.O\. BOX|POST OFFICE)"); Please help

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Put ^ at the start of the pattern to match the start of the string.

      Despite everything, the person most likely to be fooling you next is yourself.

      N 1 Reply Last reply
      0
      • G Guffa

        Put ^ at the start of the pattern to match the start of the string.

        Despite everything, the person most likely to be fooling you next is yourself.

        N Offline
        N Offline
        nesfrank
        wrote on last edited by
        #3

        thank you. excellent. how can that be con verted in c#?

        G 1 Reply Last reply
        0
        • N nesfrank

          thank you. excellent. how can that be con verted in c#?

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          The string literal actually looks exactly the same. In the Javascript you need to escape the backslash characters with a backslash character: var poboxPattern = new RegExp("^(APO|A\\.P\\.O\\.|A P O|FPO|F\\.P\\.O\\.|F P O|POB|P\\.O\\.B\\.|POBOX|P\\.O\\.BOX|PO BOX|P O BOX|P\\.O\\. BOX|POST OFFICE)"); In C#: RegEx postboxExpression = new RegEx("^(APO|A\\.P\\.O\\.|A P O|FPO|F\\.P\\.O\\.|F P O|POB|P\\.O\\.B\\.|POBOX|P\\.O\\.BOX|PO BOX|P O BOX|P\\.O\\. BOX|POST OFFICE)"); However, in C# you can also use a @ delimited string so that you don't need to escape the backslashes: RegEx postboxExpression = new RegEx(@"^(APO|A\.P\.O\.|A P O|FPO|F\.P\.O\.|F P O|POB|P\.O\.B\.|POBOX|P\.O\.BOX|PO BOX|P O BOX|P\.O\. BOX|POST OFFICE)");

          Despite everything, the person most likely to be fooling you next is yourself.

          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