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. 4 8278
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...
"Stitch Jones" <st******@nycap .rr.com> wrote in message
news:fs******** *************** *********@4ax.c om... 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
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 Area (CMSA)</td><td
align="left"><strong> SEATTLE-TACOMA-BREMERTON, WA
( 7602 )</td></tr>
<tr><td align="right">Primary Metro Area (PMSA)</td><td
align="left"><strong>SEATTLE-BELLEVUE-EVERETT, WA
( 7600 )</td></tr>
|
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 regular expressions
easier to create and use (and in my experience as a regular expression
user, it makes them MUCH easier to create and use.)
I'm still working on formal documentation, and in any case, such
documentation isn't necessarily the...
|
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
testMyColumn{1, 100}Test
Basically I want the regular expression to add the word test infront of the
|
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 over
each document, find out if it contains a header and/or a footer and
extract only the main content part.
The headers and the footers have no specific format and I have to
detect and remove them using a list of strings that may appear as...
|
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 = re.compile('(?<=\S)+$', re.MULTILINE)
1) Windows
>>> r="erewr \r\nafjdskl "
| |
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 (CONDUCTION
DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH
CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How
do I gain access to the expression (not the matches) at runtime?
Thanks,
Mike
|
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 regular expressions are correct as I got them from
regexlib.com and tested them in the Regulator and Expresso.
The problem is I tested this function with a file that contains a string
|
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 expression that only returns part of a
string.
For Example I have a multi-line text fragment like below:
|
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/
Returned value will be --> My organisation is great!
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |