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. Linux, Apache, MySQL, PHP
  4. how to preg_replace the last comma?

how to preg_replace the last comma?

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
questionregextutorial
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.
  • M Offline
    M Offline
    mabrahao
    wrote on last edited by
    #1

    what is the regex to replace only the last comma, using preg_replace? Thanks

    P 1 Reply Last reply
    0
    • M mabrahao

      what is the regex to replace only the last comma, using preg_replace? Thanks

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      It goes something like /,[^,]*$/ Fire up expresso and try it. The logic is "comma, any number of non-commas, end" So all but the last comma will fail the second part. Cheers, Peter ps There is a regex forum here. Next time...

      Software rusts. Simon Stephenson, ca 1994.

      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