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 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
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
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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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:...
|
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...
|
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...
| |
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...
|
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...
|
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....
|
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...
|
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 (ö), but FF throws an error...
|
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: 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.
|
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...
| |