need help for regex

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex Shi

    need help for regex

    Hello folks,

    I want to retrieve full name, city name, state and country from
    following string:
    "(Firstname Lastname - Traverse City, MI United States)"

    I think maybe a regex can be a solution. However I don't have
    much knowledge on it. I need help. Thanks in advance!

    Alex Shi

  • John Dunlop

    #2
    Re: need help for regex

    Alex Shi wrote:
    [color=blue]
    > I want to retrieve full name, city name, state and country from
    > following string:
    > "(Firstname Lastname - Traverse City, MI United States)"[/color]

    No more constraints? What does a state name look like, for example?

    preg_match(
    '`\((.*) - (.*), ([A-Z]{2}) ([^)]*)\)`sU',
    $string,
    $array);

    --
    Jock

    Comment

    • Tim Van Wassenhove

      #3
      Re: need help for regex

      On 2004-03-07, Alex Shi <chpshi@stonix. com> wrote:[color=blue]
      > Hello folks,
      >
      > I want to retrieve full name, city name, state and country from
      > following string:
      > "(Firstname Lastname - Traverse City, MI United States)"
      >
      > I think maybe a regex can be a solution. However I don't have
      > much knowledge on it. I need help. Thanks in advance![/color]

      Have a look at http://be.php.net/manual/en/function.sscanf.php

      --

      Comment

      • R. Rajesh Jeba Anbiah

        #4
        Re: need help for regex

        "Alex Shi" <chpshi@stonix. com> wrote in message news:<ZPt2c.743 69$oA1.72282@nn tp-post.primus.ca> ...[color=blue]
        > Hello folks,
        >
        > I want to retrieve full name, city name, state and country from
        > following string:
        > "(Firstname Lastname - Traverse City, MI United States)"
        >
        > I think maybe a regex can be a solution. However I don't have
        > much knowledge on it. I need help. Thanks in advance![/color]

        This might help you <http://www.weitz.de/regex-coach/>

        --
        "I don't believe in the God who doesn't give me food, but shows me
        heaven!"--Swami Vivekanandha
        Email: rrjanbiah-at-Y!com

        Comment

        Working...