SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast jagat_21's Avatar
    Join Date
    Jun 2007
    Location
    Ahmedabad,India
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regular Expression Problem

    Hi all,

    i have following written following regular expression :

    ([^)-0-9]*)([^-,]*)-([^-,]*)$


    i have string in following format :

    test 1 - test 2 - test 3

    Using above expression i m getting middle part i.e. test 2 as a result.

    Now the problem is that if the string doesnt contain any - (dash) then the above regular expression doesnt get anything as result.

    let say i have following string :

    test 1.

    then it wont select anything.

    Please help me in this so that the regular expression can work for both the given string formats.


    Thanks in advance.

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    It wont match anything as there is nothing to match too.
    You are asking the regex to grab everything between the - and - but if there are no -- then what can it match too?!

    What are you trying to do with this?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •