473,396 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 8266
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: MJ | last post by:
I'm having problems coming up with a regular expression that works for what I want. I need to extract a few numbers from from html. Here's a snippet: <tr><td align="right">Consolidated Metro...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
17
by: Franz Steinhaeusler | last post by:
Hello, I need a regularexpression, which trims trailing whitespaces. While with unix line endings, it works; but not with Window (Dos) CRLF's: >>> import re >>> retrailingwhitespace =...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
3
by: Chris | last post by:
Hi everyone, I'm trying to parse through the contents of some text files with regular expressions, but am new to regular expressions and how to use them in VB.net. I'm pretty sure that the...
3
by: Mr.Steskal | last post by:
Posted: Wed Jul 11, 2007 7:01 am Post subject: Regular Expression Help -------------------------------------------------------------------------------- I need help writing a regular...
2
by: shaoen01 | last post by:
Hi, I am new to Perl and stumbled onto some regular expressions and not sure if i am right in interpreting it. If my text is "My organization is great!" Regular express used: s/z*/s/ ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.