473,513 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing entities

Hello all

I need to build a program that check the sintax in a line:

SIZE (1 BYTE)

and change the correct number of bytes to the following format:

SIZE(1)

without the "BYTE" word. But, the number of bytes can be over 3 digits,
and the entitie can't have spaces but the correct number of bytes in
parentheses, like "SIZE (1024 BYTE)" to "SIZE(1024)".

Does anyone already done this or similar sintax using re?

Thank you

Jul 19 '05 #1
6 1141
Daniel wrote:
Hello all

I need to build a program that check the sintax in a line:

SIZE (1 BYTE)

and change the correct number of bytes to the following format:

SIZE(1)

without the "BYTE" word. But, the number of bytes can be over 3 digits,
and the entitie can't have spaces but the correct number of bytes in
parentheses, like "SIZE (1024 BYTE)" to "SIZE(1024)".

import re
byter = re.compile(r'SIZE \((\d+) BYTE\)')
s = 'SIZE (1 BYTE)'
byter.sub(r'SIZE(\1)', s) 'SIZE(1)' s = 'SIZE (1024 BYTE)'
byter.sub(r'SIZE(\1)', s)

'SIZE(1024)'

Kent
Jul 19 '05 #2
Hi Kent

Thanks for your help, it worked sucessfully. I have another question, I
think it is a stupid and simple but...

I need match a regular expression, change it erasing the other strings
after this. Just like:

a = "I'm going send to out of space, find another race"

And I want to match "space" instance, and erase the other.

Thank you

Jul 19 '05 #3
Daniel wrote:
I need match a regular expression, change it erasing the other strings
after this. Just like:

a = "I'm going send to out of space, find another race"

And I want to match "space" instance, and erase the other.


If you mean you want to get rid of everything after 'space', this will do it:
import re
a = "I'm going send to out of space, find another race"
re.sub('space.*', 'space', a)

"I'm going send to out of space"

You should read this and learn to make your own regexes:
http://www.amk.ca/python/howto/regex/

Kent
Jul 19 '05 #4
Hi Kent

This isn't work with the following line:
FieldGraphic56 ::= GraphicString EBCDIC BC= " " SIZE (56
BYTES)
byter = re.compile(r'SIZE \((\d+) BYTE\)')
s = 'SIZE (1 BYTE)'
byter.sub(r'SIZE(\1)', s) 'SIZE(1)' byter.sub(r'SIZE(\1)', line) 'FieldGraphic56 ::= GraphicString EBCDIC BC= " " SIZE (56
BYTES)' line 'FieldGraphic56 ::= GraphicString EBCDIC BC= " " SIZE (56
BYTES)'


Any idea? :-p

Jul 19 '05 #5
Hi Kent

This isn't work with the following line:
FieldGraphic56 ::= GraphicString EBCDIC BC= " " SIZE (56
BYTES)
byter = re.compile(r'SIZE \((\d+) BYTE\)')
s = 'SIZE (1 BYTE)'
byter.sub(r'SIZE(\1)', s) 'SIZE(1)' byter.sub(r'SIZE(\1)', line) 'FieldGraphic56 ::= GraphicString EBCDIC BC= " " SIZE (56
BYTES)' line 'FieldGraphic56 ::= GraphicString EBCDIC BC= " " SIZE (56
BYTES)'


Any idea? :-p

Jul 19 '05 #6
Daniel wrote:
Hi Kent

This isn't work with the following line:
FieldGraphic56 ::= GraphicString EBCDIC BC= " " SIZE (56
BYTES)

byter = re.compile(r'SIZE \((\d+) BYTE\)')


Because the string doesn't match the pattern, can you see the difference? Do you understand what the regex is looking for?

Another good way to learn about regexes is with the Regex Demo program distributed with Python. Look for Tools\Scripts\redemo.py

Kent
Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4344
by: Kunle Odutola | last post by:
I have a database that tracks players for children's sports clubs. I have included representative DDL for this database at the end of this post. A single instance of this database supports...
1
1254
by: sylvain.loiseau | last post by:
It's not so clear for me, in the xml spec, which is the required behaviour of an XML processor for entities : - The characters entities (predefined, decimal and hexadecimal) must be expended and...
2
5967
by: Nick Craig-Wood | last post by:
I'm using xml.minidom to parse some of our XML files. Some of these have entities like "°" in which aren't understood by xml.minidom. These give this error. xml.parsers.expat.ExpatError:...
3
2544
by: Michel de Becdelièvre | last post by:
I have some *performance* trouble reading MathML files in my application (in ASP.Net). - I have small MathML files (2-3k) as input - as (almost) all MathML files these use entities. I have no...
1
2002
by: David Bertoni | last post by:
Hi all, I'm trying to resolve what appears to me an inconsistency in the XML 1.0 recommendation involving entities encoding in UTF-16 and the requirement for a byte order mark. Section 4.3.3...
2
2791
by: Frantic | last post by:
I'm working on a list of japaneese entities that contain the entity, the unicode hexadecimal code and the xml/sgml entity used for that entity. A unicode document is read into the program, then the...
6
10124
by: clintonG | last post by:
Can anybody make sense of this crazy and inconsistent results? // IE7 Feed Reading View disabled displays this raw XML <?xml version="1.0" encoding="utf-8" ?> <!-- AT&T HTML entities & XML...
3
2054
by: bsagert | last post by:
Some web feeds use decimal character entities that seem to confuse Python (or me). For example, the string "doesn't" may be coded as "doesn’t" which should produce a right leaning apostrophe....
7
2539
by: tempest | last post by:
Hi all. This is a rather long posting but I have some questions concerning the usage of character entities in XML documents and PCI security compliance. The company I work for is using a...
1
2733
Dormilich
by: Dormilich | last post by:
Hi, I got a strange behaviour (FF 3) of entities in my xml files. I have an element (see xml listing), where the attribute/content contains a latin1 entity (&ouml;), but FF throws an error...
0
7260
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
7161
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...
1
7101
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
5686
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,...
0
3234
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...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1596
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 ...
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
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...

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.