469,271 Members | 1,000 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Regular Express to remove all text between to ,'s

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.
Jul 19 '05 #1
4 8135
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...
Jul 19 '05 #2
"Stitch Jones" <st******@nycap.rr.com> wrote in message
news:fs********************************@4ax.com...
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

Jul 19 '05 #3
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
Jul 19 '05 #4
On Sun, 22 Aug 2004 12:20:12 -0400, "Shawn Zabel" <za*****@alltel.net>
wrote:
"Stitch Jones" <st******@nycap.rr.com> wrote in message
news:fs********************************@4ax.com.. .
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.
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by MJ | last post: by
4 posts views Thread by Buddy | last post: by
4 posts views Thread by Neri | last post: by
17 posts views Thread by Franz Steinhaeusler | last post: by
25 posts views Thread by Mike | last post: by
3 posts views Thread by Mr.Steskal | last post: by
2 posts views Thread by shaoen01 | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.