AutoHotkey Community

It is currently May 27th, 2012, 2:30 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: February 11th, 2010, 5:46 am 
Hi all,

I have a problem I just can not get solved.

Say I have a text like this:

My {dog|cat} is a pet, which is not {good|great|fantastic}. I always need to {feed it|give it food}. It drives {me|us|my family} {crazy|insane} {and|and also} eats {my|our} {newspaper|papers}.

I need to extract all strings that are in {...} to a seperate file.

So for this example I would get a file like this:

{dog|cat}
{good|great|fantastic}
{feed it|give it food}
{me|us|my family}
{crazy|insane}
{and|and also}
{my|our}
{newspaper|papers}


Has somebody an idea how I can achieve that?

This would help me a lot :)

Thank you very much!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2010, 5:53 am 
Offline

Joined: March 9th, 2007, 2:47 am
Posts: 509
Location: Unknown
There are many different ways to approach this. You could use any of the following commands.
http://www.autohotkey.com/docs/commands/RegExMatch.htm
http://www.autohotkey.com/docs/commands/LoopParse.htm
http://www.autohotkey.com/docs/commands/StringLeft.htm
http://www.autohotkey.com/docs/commands/StringSplit.htm
http://www.autohotkey.com/docs/commands/StringTrimLeft.htm


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2010, 6:33 am 
There is a grep function that you can use.
Code:
text = My {dog|cat} is a pet, which is not {good|great|fantastic}. I always need to {feed it|give it food}. It drives {me|us|my family} {crazy|insane} {and|and also} eats {my|our} {newspaper|papers}.

grep(text, "({.*?})", matches,1,0,"`n")
msgbox, %matches%

; grep function: http://www.autohotkey.com/forum/topic16164.html
grep(h, n, ByRef v, s = 1, e = 0, d = "") {
   v =
   StringReplace, h, h, %d%, , All
   Loop
      If s := RegExMatch(h, n, c, s)
         p .= d . s, s += StrLen(c), v .= d . (e ? c%e% : c)
      Else Return, SubStr(p, 2), v := SubStr(v, 2)
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2010, 6:53 am 
Offline

Joined: December 18th, 2009, 6:08 pm
Posts: 63
im sure there is a better way, maybe one of the pros will chime in, but here is my attempt..
Code:
test = My {dog|cat} is a pet, which is not {good|great|fantastic}. I always need to {feed it|give it food}. It drives {me|us|my family} {crazy|insane} {and|and also} eats {my|our} {newspaper|papers}.

Loop, Parse, test, }
{
newtest = %A_LoopField%`}
RegExMatch(newtest, "\{.+?\}", output)
msgbox, %output%
}


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Alpha Bravo, Bing [Bot], LazyMan, rbrtryn and 18 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