Regular Express to remove all text between to ,'s

Discussion in 'Perl' started by Stitch Jones, Aug 22, 2004.

  1. Stitch Jones

    Stitch Jones Guest

    I'm trying to get part of my perl script using a regex to get rid of
    an entire field between two ,'s I'm doing this to get a .csv formated
    alot nicer. here is an example of my issue
    user ,jibberjibber 1234456hithere(hkl)- special char [0]jibber, 4567
    I need the keep the user part and the end 4567 part but all the stuff
    between the two ,'s has gotta go. Someone Please help.
    Thank you.
    Stitch Jones, Aug 22, 2004
    #1
    1. Advertising

  2. Stitch Jones wrote:

    > I'm trying to get part of my perl script using a regex to get rid of
    > an entire field between two ,'s I'm doing this to get a .csv formated
    > alot nicer. here is an example of my issue
    > user ,jibberjibber 1234456hithere(hkl)- special char [0]jibber, 4567
    > I need the keep the user part and the end 4567 part but all the stuff
    > between the two ,'s has gotta go. Someone Please help.
    > Thank you.


    s!^([^,]*),[^,]*?,(.*)$!$1$2!;

    This assumes that the line given is formatted as you defined and you only
    want to remove the first lot of comma defined text.


    --
    Simon Proctor
    http://www.khanate.dnsalias.org/
    Sometimes you just have to wonder...
    Simon Proctor, Aug 22, 2004
    #2
    1. Advertising

  3. Stitch Jones

    Shawn Zabel Guest

    "Stitch Jones" <> wrote in message
    news:...
    > I'm trying to get part of my perl script using a regex to get rid of
    > an entire field between two ,'s I'm doing this to get a .csv formated
    > alot nicer. here is an example of my issue
    > user ,jibberjibber 1234456hithere(hkl)- special char [0]jibber, 4567
    > I need the keep the user part and the end 4567 part but all the stuff
    > between the two ,'s has gotta go. Someone Please help.
    > Thank you.



    The following regex will substitute everything between the first and last
    comma (including the commas on each end) with a comma. The result based on
    your example will be "user , 4567" without the quotes.

    s/,.*,/,/


    - Shawn
    Shawn Zabel, Aug 22, 2004
    #3
  4. Stitch Jones

    Joe Smith Guest

    Stitch Jones wrote:

    > I'm trying to get part of my perl script using a regex to get rid of
    > an entire field between two ,'s


    What have you tried? Post a snippet of your code to the proper
    newsgroup (comp.lang.perl.misc) instead of here (comp.lang.perl).
    [Do you know the difference between s/,.*,/,/ and s/,.*?,/,/ ?]
    -Joe
    Joe Smith, Aug 22, 2004
    #4
  5. Stitch Jones

    Stitch Jones Guest

    On Sun, 22 Aug 2004 12:20:12 -0400, "Shawn Zabel" <>
    wrote:

    >"Stitch Jones" <> wrote in message
    >news:...
    >> I'm trying to get part of my perl script using a regex to get rid of
    >> an entire field between two ,'s I'm doing this to get a .csv formated
    >> alot nicer. here is an example of my issue
    >> user ,jibberjibber 1234456hithere(hkl)- special char [0]jibber, 4567
    >> I need the keep the user part and the end 4567 part but all the stuff
    >> between the two ,'s has gotta go. Someone Please help.
    >> Thank you.

    >
    >
    >The following regex will substitute everything between the first and last
    >comma (including the commas on each end) with a comma. The result based on
    >your example will be "user , 4567" without the quotes.
    >
    >s/,.*,/,/
    >
    >
    >- Shawn
    >
    >


    Shawn, Thank you. That was what I needed. I was overthinking it. I
    thought I needed to come up with a fancy string to parse through it.
    I'll have to start brushing up on my Reg-Ex 101 stuff.
    Thank You.
    Stitch Jones, Aug 22, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ad
    Replies:
    7
    Views:
    654
    Scott Allen
    Apr 11, 2005
  2. =?Utf-8?B?Q2FybCBNLg==?=
    Replies:
    4
    Views:
    2,460
    sivlookingforu
    Aug 7, 2006
  3. brooksr
    Replies:
    3
    Views:
    324
    Jon Paal
    Dec 24, 2006
  4. Jake Henderson

    Visual Web Developer 2005 Express and SQL 2005 Express

    Jake Henderson, Mar 10, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    208
    Jake Henderson
    Mar 10, 2006
  5. Robert
    Replies:
    10
    Views:
    1,550
    Robin
    Apr 21, 2004
Loading...

Share This Page