AutoHotkey Community

It is currently May 27th, 2012, 3:41 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: July 20th, 2010, 3:50 pm 
Offline

Joined: March 18th, 2009, 3:06 pm
Posts: 17
Location: Minnesota, USA
I'd like to remove all of the carriage returns and field names so that I just have the data. I will later replace the AAAA with commas.

I've been working on this for a few hours, searching the forums, regex tutorials, the AHK manual and testing. I think I'm close, but I can't get it to work. Any help would be greatly appreciated.

Thanks,
Pete

Code:
StrOut=
(
   



Description=NVIDIA nForce Networking Controller - Packet Scheduler Miniport

IPAddress="192.168.11.21"

IPSubnet="255.255.255.0"

MACAddress=00:1D:7D:B8:29:09





Description=VirtualBox Host-Only Ethernet Adapter - Packet Scheduler Miniport

IPAddress="192.168.54.20"

IPSubnet="255.255.255.0"

MACAddress=08:00:27:00:84:B9

)


  StrOut := RegExReplace(StrOut, "(/R*?=)", "AAAA")
  MsgBox, %StrOut%
  ExitApp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2010, 4:29 pm 
Is this what you want?
Code:
MsgBox, % StrOut := RegExReplace(StrOut, "s)\n.*?=", "`n")


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2010, 4:32 pm 
Offline

Joined: August 8th, 2007, 5:41 am
Posts: 136
Location: Michigan
Code:
StrOut=
(
Description=NVIDIA nForce Networking Controller - Packet Scheduler Miniport

IPAddress="192.168.11.21"

IPSubnet="255.255.255.0"

MACAddress=00:1D:7D:B8:29:09

Description=VirtualBox Host-Only Ethernet Adapter - Packet Scheduler Miniport

IPAddress="192.168.54.20"

IPSubnet="255.255.255.0"

MACAddress=08:00:27:00:84:B9

)

loop
{
BEG := InStr(Strout, "=")
if BEG = 0
          Break
StringTrimLeft, Strout, Strout, %BEG%
END := InStr(Strout, "`n")
StringLeft, results, Strout, %End%
Final = %Final%`n %results%
}
msgbox, %final%


Not regex but it worked. If you want the " gone around the IPs and stuff to just add in this line after the StringLeft line:
StringReplace, results, results, ",,all ***this is not tested but I am pretty sure it will work***


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2010, 5:02 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
You need to run two unique RegExReplace calls:

Code:
StrOut=
(
   



Description=NVIDIA nForce Networking Controller - Packet Scheduler Miniport

IPAddress="192.168.11.21"

IPSubnet="255.255.255.0"

MACAddress=00:1D:7D:B8:29:09





Description=VirtualBox Host-Only Ethernet Adapter - Packet Scheduler Miniport

IPAddress="192.168.54.20"

IPSubnet="255.255.255.0"

MACAddress=08:00:27:00:84:B9

)


StrOut :=   RegExReplace(RegExReplace(StrOut,"\v{2,}","`r`n"),"ism)^\w+=")
MsgBox, %   StrOut
return

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 21st, 2010, 2:55 pm 
Offline

Joined: March 18th, 2009, 3:06 pm
Posts: 17
Location: Minnesota, USA
Thank you for all of the replies. a4u, That seems to do everything, but it still leaves either a carriage return or line feed between each result. Sinkfaze, that works great for my current problem, though then I realized I will also need to parse the same data a different way as well. These are the results of WMI queries that I'm trying to reformat into sqlite statements. Is there a way to insert a string of characters such as $# between the 2 records in the example? I will replace these later with my sqlite query.

I've spent a few hours trying to learn more about regex, but am still having trouble figuring out how your regex works. Do you have any suggestions for good resources to learn regex.

Thanks,
Pete


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 21st, 2010, 3:39 pm 
How about:
Code:
MsgBox, % StrOut := RegExReplace(StrOut, "s)[\r\n]+.*?=", "`n") ; remove the "`n" if you want all the results on the same line

http://www.autohotkey.com/docs/misc/RegEx-QuickRef.htm
http://www.autohotkey.com/wiki/index.ph ... =Tutorials
http://www.autohotkey.com/forum/topic43197.html


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 21st, 2010, 5:58 pm 
Offline

Joined: March 18th, 2009, 3:06 pm
Posts: 17
Location: Minnesota, USA
Thanks a4u, Yes that works well too for my first problem. I'm assuming that the single regexreplace will be faster than the one that sinkfaze posted? Not that it will probably matter much at this point because the amount of data that I'm searching through is fairly small, but just for future reference. I'm reading through Sinkfaze's excellent tutorial now that you linked to and I'm realizing how powerful regex is. I'm pretty sure I will be able to figure out my second question on my own after reading the tutorial. I will post the answer here if/when I come up with it.
Thanks,
Pete


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 21st, 2010, 7:09 pm 
Offline

Joined: March 18th, 2009, 3:06 pm
Posts: 17
Location: Minnesota, USA
Woohoo! This is what worked. Thank you everyone. Turns out I didn't need regex for the second part of this task (or first depending on how you read it), but I've learned a great deal more about it with your help.

Code:
 
StrOut=
(
   



Description=NVIDIA nForce Networking Controller - Packet Scheduler Miniport

IPAddress="192.168.11.21"

IPSubnet="255.255.255.0"

MACAddress=00:1D:7D:B8:29:09





Description=VirtualBox Host-Only Ethernet Adapter - Packet Scheduler Miniport

IPAddress="192.168.54.20"

IPSubnet="255.255.255.0"

MACAddress=08:00:27:00:84:B9

)

StringReplace, StrOut,StrOut, `r`r`n`r`r`n`r`r`n, $?, All
StrOut := RegExReplace(StrOut, "s)[\r\n]+.*?=", "'`,'")


I will still need to trim a little and add my sqlite syntax, but this will work.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], bobbysoon, Google Feedfetcher, Wicked, Yahoo [Bot] and 17 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group