Replacing Periods with Backspaces

B

Booter

All,

I am trying to replace a series of periods in a sting with backspaces
that way I can easily parse information from a Windows command. the
current statement I have for this is

***************************Statement************************************
capture = re.sub('\.*', '\b', capture)

===Out Put===
str: \bi\bp\bc\bo\bn\bf\bi\bg\b \b/\ba\bl\bl\b\n\b\n\bW\bi\bn\bd\bo\bw
\bs\b \bI\bP\b \bC\bo\bn\bf\bi\bg\bu\br\ba\bt\bi\bo\bn\b\n\b\n\b \b \b
\bH\bo\bs\bt\b \bN\ba\bm\be\b \b \b \b \b \b \b \b \b \b \b \b \b \b:
\b \bT\br\bi\bt\bo\bn\b\n\b \b \b \bP\br\bi\bm\ba\br\by\b \bD\bn\bs\b
\bS\bu\bf\bf\bi\bx\b \b \b \b \b \b \b \b \b \b:\b \be\bn\bg\br\bC\bo
\bl\bo\bS\bt\ba\bt\be\bE\bD\bU\b\n\b \b \b \bN\bo\bd\be\b \bT\by\bp\be
\b \b \b \b \b \b \b \b \b \b \b \b \b \b:\b \bH\by\bb\br\bi\bd\b\n\b
\b \b \bI\bP\b \bR\bo\bu\bt\bi\bn\bg\b \bE\bn\ba\bb\bl\be\bd\b \b \b
\b \b \b \b \b \b:\b \bN\bo\b\n\b \b \b \bW\bI\bN\bS\b \bP\br\bo\bx\by
\b \bE\bn\ba\bb\bl\be\bd\b \b \b \b \b \b \b \b \b:\b \bN\bo\b\n\b \b
\b \bD\bN\bS\b \bS\bu\bf\bf\bi\bx\b \bS\be\ba\br\bc\bh\b \bL\bi\bs\bt
\b \b \b \b \b \b \b:\b \be\bn\bg\br\bC\bo\bl\bo\bS\bt\ba\bt\be\bE\bD
\bU\b\n\b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b
\b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \bC\bo\bl\bo\bS
\bt\ba\bt\be\bE\bD\bU\b\n\b\n\bE\bt\bh\be\br\bn\be\bt\b \ba\bd\ba\bp\bt
\be\br\b \bL\bo\bc\ba\bl\b \bA\br\be\ba\b \bC\bo\bn\bn\be\bc\bt\bi\bo
\bn\b:\b\n\b\n\b \b \b \bC\bo\bn\bn\be\bc\bt\bi\bo\bn\b-\bs\bp\be\bc\bi
\bf\bi\bc\b \bD\bN\bS\b \bS\bu\bf\bf\bi\bx\b \b \b \b:\b \b\n\b \b \b
\bD\be\bs\bc\br\bi\bp\bt\bi\bo\bn\b \b \b \b \b \b \b \b \b \b \b \b
\b:\b \bR\be\ba\bl\bt\be\bk\b \bP\bC\bI\be\b \bG\bB\bE\b \bF\ba\bm\bi
\bl\by\b \bC\bo\bn\bt\br\bo\bl\bl\be\br\b\n\b \b \b \bP\bh\by\bs\bi\bc
\ba\bl\b \bA\bd\bd\br\be\bs\bs\b \b \b \b \b \b \b...
==============================END============================

which paces a bunch of '\b' strings throughout the string (to me at
random). It sort of works if I use this command but I don't want
there to be whitespace...

**************************Statement***************************************
capture = re.sub('\.*', '\b', capture)

===Out Put===
str: ipconfig /all\n\nWindows IP Configuration\n\n Host
Name : Triton\n Primary Dns Suffix :
engrColoStateEDU\n Node Type : Hybrid\n IP Routing
Enabled : No\n WINS Proxy Enabled : No\n DNS Suffix
Search List : engrColoStateEDU
\n ColoStateEDU\n\nEthernet
adapter Local Area Connection:\n\n Connection-specific DNS
Suffix : \n Description : Realtek PCIe GBE Family
Controller\n Physical Address : 00-24-1D-16-FF-28\n DHCP
Enabled : No\n Autoconfiguration Enabled : Yes\n
IPv4 Address : 12982227254(Preferred) \n Subnet
Mask : 2552552480\n Default Gateway :
129822241\n DNS Servers :
1298210378\n 1298210379\n
NetBIOS over Tcpip : Enabled\n\nTunnel adapter
isatap{04FB4DF5-4B41-4058-A641-6965D13CCC06}:\n\n Media
State : Media disconnected\n Connection-specific DNS
Suffix ...
==============END================================


If anyone can help it would be greatly appreciated.

Thanks,

Gerad Bottorff
 
G

Gabriel Genellina

I am trying to replace a series of periods in a sting with backspaces
that way I can easily parse information from a Windows command. the
current statement I have for this is

***************************Statement************************************
capture = re.sub('\.*', '\b', capture)

The * means "ZERO or more" occurrences - matching practically everywhere.
I think you want \.+ -- one or more occurrences of a literal period. To
actually have a \ in the string, you have to write it as "\\.+" or r"\.+"
===Out Put===
str: \bi\bp\bc\bo\bn\bf\bi\bg\b \b/\ba\bl\bl\b\n\b\n\bW\bi\bn\bd\bo\bw
\bs\b \bI\bP\b \bC\bo\bn\bf\bi\bg\bu\br\ba\bt\bi\bo\bn\b\n\b\n\b \b \b
==============================END============================

which paces a bunch of '\b' strings throughout the string (to me at
random). It sort of works if I use this command but I don't want
there to be whitespace...

You want those \b, don't you? Just not everywhere...
===Out Put===
str: ipconfig /all\n\nWindows IP Configuration\n\n Host
Name : Triton\n Primary Dns Suffix :
engrColoStateEDU\n Node Type : Hybrid\n IP Routing
Enabled : No\n WINS Proxy Enabled : No\n DNS Suffix
Search List : engrColoStateEDU
\n ColoStateEDU\n\nEthernet
adapter Local Area Connection:\n\n Connection-specific DNS
Suffix : \n Description : Realtek PCIe GBE Family
Controller\n Physical Address : 00-24-1D-16-FF-28\n DHCP
Enabled : No\n Autoconfiguration Enabled : Yes\n
IPv4 Address : 12982227254(Preferred) \n Subnet
Mask : 2552552480\n Default Gateway :
129822241\n DNS Servers :
1298210378\n 1298210379\n
NetBIOS over Tcpip : Enabled\n\nTunnel adapter
isatap{04FB4DF5-4B41-4058-A641-6965D13CCC06}:\n\n Media
State : Media disconnected\n Connection-specific DNS
Suffix ...
==============END================================

Except for the last '...' I don't see any '.' in that string to be
replaced...
 
A

Aahz

I am trying to replace a series of periods in a sting with backspaces
that way I can easily parse information from a Windows command. the
current statement I have for this is

capture = re.sub('\.*', '\b', capture)

What's wrong with

capture = capture.replace('.', '\b')

That will be much faster.
--
Aahz ([email protected]) <*> http://www.pythoncraft.com/

"...string iteration isn't about treating strings as sequences of strings,
it's about treating strings as sequences of characters. The fact that
characters are also strings is the reason we have problems, but characters
are strings for other good reasons." --Aahz
 
B

Booter

All,

Thanks for all the help I finally got it. I ended up not having to
get rid of the periods.

Thanks again!

Gerad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,108
Latest member
AlbertEste
Top