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 1118
On Thu, 25 Sep 2008 15:51:28 +0100, ji*********@gma il.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(i tem.split('/'))
yield tuple(result)
result = list()
else:
result.append(i tem)
def main():
string = '12560/ABC,12567/BC,123,567,890/JK'
print list(group(stri ng))
Ciao,
Marc 'BlackJack' Rintsch
On Sep 25, 6:34*pm, Marc 'BlackJack' Rintsch <bj_...@gmx.net wrote:
On Thu, 25 Sep 2008 15:51:28 +0100, jitensha...@gma il.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(i tem.split('/'))
* * * * * * yield tuple(result)
* * * * * * result = list()
* * * * else:
* * * * * * result.append(i tem)
def main():
* * string = '12560/ABC,12567/BC,123,567,890/JK'
* * print list(group(stri ng))
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...@gm ail.com" <jitensha...@gm ail.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(W ord(nums)) + SLASH + Word(alphas) dataformat = delimitedList(G roup(dataitem)) map(tuple, dataformat.pars eString(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 = '1.0'?>
<person><who>scott</who></person>
|
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 (still an XSLT
n00b), but I'm not sure that's the way to go anyway...
What I'm trying to accomplish is generation of XML Schema output from a
given XML input, with "xs:import" elements in the output with the
"namespace" and "schemaLocation"...
|
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 received by the internet explorer, after they are transformed
with an xslt by the framework.
now the problem that we are facing is like - the explorer extracts the
text inside all xml tags
of the response xml and shows it as simple text. but, if you...
|
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 like to split it and create a new
file at every lets say 20000 lines... so, the directory output would
have to be something like this:
| |
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 know one way or the other whether that was
true or not, or could point me to an article or help text that would. What I
have seen so far online and in Access 2007 help seems to confirm the above.
But that (or at least (b)) seems incredible that it...
|
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 me to "clean up that mess you never use anyway and please dump the
rest of it in the attic or simply throw that junk away".
I want to make a statement here:
|
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
attachment contains the complete source code which was explained in the previous
article parts. Download it, extract the sources somewhere and have a look.
The data I've been using all the time can be found here. There are
|
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 elisp, first take a gander at Emacs Lisp Basics.
HTML version with links and colors is at:
http://xahlee.org/emacs/elisp_text_processing.html
|
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 I draw (call) a messagebox, then the
text appears. What can it be? I had made a total new one, but did'nt help.
|
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: 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: 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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: 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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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: 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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |