regex help

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

    regex help

    i need a regex that matches either
    /ABC/
    or
    /ABC/DEF/

    I came up with
    /(.*)/(.*)/

    how do i make the second part optional?
    thx
    Tem
  • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

    #2
    Re: regex help

    Tem wrote:
    i need a regex that matches either
    /ABC/
    or
    /ABC/DEF/
    >
    I came up with
    /(.*)/(.*)/
    >
    how do i make the second part optional?
    ? and ?? means 0 or 1 occurrences.

    Arne

    PS: . also match / !

    Comment

    • Tem

      #3
      Re: regex help

      I tried

      /(.*)/?(.*)?/

      to match

      /ABC/
      /ABC/DEF/

      /ABC/ returned ABC and null which is correct
      but /ABC/DEF/ returned ABC/DEF and null
      is should return ABC and DEF

      thanks

      "Arne Vajhøj" <arne@vajhoej.d kwrote in message
      news:4841d1c5$0 $90275$14726298 @news.sunsite.d k...
      Tem wrote:
      >i need a regex that matches either
      >/ABC/
      >or
      >/ABC/DEF/
      >>
      >I came up with
      >/(.*)/(.*)/
      >>
      >how do i make the second part optional?
      >
      ? and ?? means 0 or 1 occurrences.
      >
      Arne
      >
      PS: . also match / !

      Comment

      • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

        #4
        Re: regex help

        Tem wrote:
        "Arne Vajhøj" <arne@vajhoej.d kwrote in message
        news:4841d1c5$0 $90275$14726298 @news.sunsite.d k...
        >Tem wrote:
        >>i need a regex that matches either
        >>/ABC/
        >>or
        >>/ABC/DEF/
        >>>
        >>I came up with
        >>/(.*)/(.*)/
        >>>
        >>how do i make the second part optional?
        >>
        >? and ?? means 0 or 1 occurrences.
        >PS: . also match / !
        I tried
        >
        /(.*)/?(.*)?/
        >
        to match
        >
        /ABC/
        /ABC/DEF/
        >
        /ABC/ returned ABC and null which is correct
        but /ABC/DEF/ returned ABC/DEF and null
        is should return ABC and DEF
        Did you note the PS ?

        Try with [^/]* instead of .* !

        Arne

        Comment

        Working...