I have string like follow
12560/ABC,12567/BC,123,567,890/JK
I want above string to group like as follow
(12560,ABC)
(12567,BC)
(123,567,890,JK)
i try regular expression i am able to get first two not the third one.
can regular expression given data in different groups 3 1109
On Thu, 25 Sep 2008 15:51:28 +0100, ji*********@gmail.com wrote:
I have string like follow
12560/ABC,12567/BC,123,567,890/JK
I want above string to group like as follow (12560,ABC)
(12567,BC)
(123,567,890,JK)
i try regular expression i am able to get first two not the third one.
can regular expression given data in different groups
Without regular expressions:
def group(string):
result = list()
for item in string.split(','):
if '/' in item:
result.extend(item.split('/'))
yield tuple(result)
result = list()
else:
result.append(item)
def main():
string = '12560/ABC,12567/BC,123,567,890/JK'
print list(group(string))
Ciao,
Marc 'BlackJack' Rintsch
On Sep 25, 6:34*pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
On Thu, 25 Sep 2008 15:51:28 +0100, jitensha...@gmail.com wrote:
I have string like follow
12560/ABC,12567/BC,123,567,890/JK
I want above string to group like as follow (12560,ABC)
(12567,BC)
(123,567,890,JK)
i try regular expression i am able to get first two not the third one.
can regular expression given data in different groups
Without regular expressions:
def group(string):
* * result = list()
* * for item in string.split(','):
* * * * if '/' in item:
* * * * * * result.extend(item.split('/'))
* * * * * * yield tuple(result)
* * * * * * result = list()
* * * * else:
* * * * * * result.append(item)
def main():
* * string = '12560/ABC,12567/BC,123,567,890/JK'
* * print list(group(string))
How about :
>>string = "12560/ABC,12567/BC,123,567,890/JK" r = re.findall(r"(\d+(?:,\d+)*/\w+)", string) r
['12560/ABC', '12567/BC', '123,567,890/JK']
>>[tuple(x.replace(",", "/").split("/")) for x in r]
[('12560', 'ABC'), ('12567', 'BC'), ('123', '567', '890', 'JK')]
On Sep 25, 9:51*am, "jitensha...@gmail.com" <jitensha...@gmail.com>
wrote:
I have string like follow
12560/ABC,12567/BC,123,567,890/JK
I want above string to group like as follow
(12560,ABC)
(12567,BC)
(123,567,890,JK)
i try regular expression i am able to get first two not the third one.
can regular expression given data in different groups
Looks like each item is:
- a list of 1 or more integers, in a comma-delimited list
- a slash
- a word composed of alpha characters
And the whole thing is a list of items in a comma-delimited list
Now to implement that in pyparsing:
>>data = "12560/ABC,12567/BC,123,567,890/JK" from pyparsing import Suppress, delimitedList, Word, alphas, nums, Group SLASH = Suppress('/') dataitem = delimitedList(Word(nums)) + SLASH + Word(alphas) dataformat = delimitedList(Group(dataitem)) map(tuple, dataformat.parseString(data))
[('12560', 'ABC'), ('12567', 'BC'), ('123', '567', '890', 'JK')]
Wah-lah! (as one of my wife's 1st graders announced in one of his
school papers)
-- Paul This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Martin |
last post by:
Hallo,
can you help me writing a generic xslt transformation (useable with
xsql from oracle)? The problem is how to get the escaping characters
....
=== INPUT-File in.xml
<?xml version =...
|
by: Imran |
last post by:
hello all, I have to parse a text file and get some value in that.
text file content is as follows.
####TEXT FILE CONTENT STARTS HERE #####
/start
first
0x1234
AC
/end
|
by: daldridge |
last post by:
I have a unique-elements/sorting question (who doesn't?), but haven't
yet been able to get appropriate template/select/for-each processing
working. I don't fully grok the Muenchian technique yet...
|
by: Shyran |
last post by:
we have a java framework, where we feed a request xml. this request xml
is forwarded through
the framework, tomcat and axis, for the backend processing, and the
processing results are
again...
|
by: ivan.perak |
last post by:
Hello,
im a beginner in VB.NET... The thing i would like to do is as it
follows....
I have a text file (list of names, every name to the next line) which
is about 350000 lines long. I would...
| |
by: Neil |
last post by:
I posted a few days ago that it seems to me that the Access 2007 rich text
feature does not support: a) full text justification; b) programmatic
manipulation.
I was hoping that someone might...
|
by: JosAH |
last post by:
Greetings,
Introduction
At the end of the last Compiler article part I stated that I wanted to write
about text processing. I had no idea what exactly to talk about; until my wife
commanded...
|
by: JosAH |
last post by:
Greetings,
Introduction
Last week I was a bit too busy to cook up this part of the article series; sorry
for that. This article part wraps up the Text Processing article series. The ...
|
by: Xah Lee |
last post by:
Text Processing with Emacs Lisp
Xah Lee, 2007-10-29
This page gives a outline of how to use emacs lisp to do text
processing, using a specific real-world problem as example. If you
don't know...
|
by: Rinaldo |
last post by:
Hi,
I have a label on my dialogbox who has to change text while running. This is
what I do:
lblBackup.Text = "Bezig met de backup naar " + F1.FTPserver;
but the text does'nt appear, only if...
|
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,...
| |
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...
|
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...
|
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...
|
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: 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...
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |