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. regular expression

regular expression

Scheduled Pinned Locked Moved Web Development
data-structuresregexhelp
2 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.
  • S Offline
    S Offline
    saadani
    wrote on last edited by
    #1

    hi, i have a space seperated list of codes and the corresponding regions and countries. it looks like this AAA kairo, Egypt BBB Region, Country. i want to extract alll the information (code, region and country) from that file with a regular (if possible only one with subpatterns)expression. is it possible to make a regular expression that returns me an array that looks like this: Array(0=>Array("code","region","country"), 1=>Array(blabla)), or an associative array. can anyone please help. thanks

    E 1 Reply Last reply
    0
    • S saadani

      hi, i have a space seperated list of codes and the corresponding regions and countries. it looks like this AAA kairo, Egypt BBB Region, Country. i want to extract alll the information (code, region and country) from that file with a regular (if possible only one with subpatterns)expression. is it possible to make a regular expression that returns me an array that looks like this: Array(0=>Array("code","region","country"), 1=>Array(blabla)), or an associative array. can anyone please help. thanks

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      ([A-Z]{3})\s+([\w|\s]+)\,\s*([\w|\s]+)

      Should work based on the data you supplied, the first group looks for exactly three characters (from A to Z), then some whitespace.  The second group looks for word characters or whitespace in sequence until it hits a comma.  The third group looks for word characters or whitespace until it hits the end of line.

      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