AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: March 22nd, 2010, 4:28 pm 
Offline

Joined: February 11th, 2005, 6:31 am
Posts: 174
Location: Germany
Hi,

I'm trying to retrieve the suffix from a windowstitle with RegExMatch.
For example the title is: "Lucie Diamond.doc .tif [Schreibgeschützt] - Microsoft Office Document Imaging"

Can I search the title from behind, when I set StartingPostition = 0 to obtain ".tif" and not ".doc"?

The ahk help says:
Quote:
If StartingPosition is less than 1, it is considered to be an offset from the end of Haystack. For example, 0 starts at the last character and -1 starts at the next-to-last character.

Code:
;the search from the beginning works, but delivers ".doc "!! :(
FoundPos := RegExMatch("Lucie Diamond.doc .tif [Schreibgeschützt] - Microsoft Office Document Imaging", "\.([a-zA-Z]{3} )", SubPat)
msgbox, SubPat1:|%SubPat1%|`nSubPat2:|%SubPat2%|`nFoundPos:|%FoundPos%|

Code:
;But to start searching from the end to get ".tif " doesn't work!?
FoundPos := RegExMatch("Lucie Diamond.doc .tif [Schreibgeschützt] - Microsoft Office Document Imaging", "\.([a-zA-Z]{3} )", SubPat,0)
msgbox, SubPat1:|%SubPat1%|`nSubPat2:|%SubPat2%|`nFoundPos:|%FoundPos%|


Thanks in advance for any suggestions :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2010, 4:37 pm 
Code:
SubStr(Wintitle,1,-3)
?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2010, 4:40 pm 
Code:
FoundPos := 1
While, FoundPos := RegExMatch("Lucie Diamond.doc .tif [Schreibgeschützt] - Microsoft Office Document Imaging", "\.([a-zA-Z]{3} )", match, FoundPos+StrLen(match))
   ext := match1
MsgBox, %ext%


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2010, 5:23 pm 
Offline

Joined: February 11th, 2005, 6:31 am
Posts: 174
Location: Germany
Thank you for your answers :D

@guest: -3 doesn't work
@answer4u: What a wonderful solution!! It works like a charm!! :D

With the following code I'm able to get also an extension with four charaters like .jpeg or .tiff

Code:
FoundPos := 1
While, FoundPos := RegExMatch("Lucie Diamond.doc .jpeg [Schreibgeschützt] - Microsoft Office Document Imaging", "\.([a-zA-Z]{3} |[a-zA-Z]{4} )", match, FoundPos+StrLen(match))
   ext := match1
MsgBox, %ext%


But I still asking myself why it doesn't work with StartingPosition = 0 :shock:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2010, 5:40 pm 
It still works left-->right, here's a visual:
Code:
string := "Lucie Diamond.doc .jpeg [Schreibgeschützt] - Microsoft Office Document Imaging"
n := -3
result := "StartPos   Result"
Loop, 8
   result .= "`n" n "   >" SubStr( string, n++ )
MsgBox,  %result%


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2010, 5:41 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
This would be shorter:

Code:
var := "Lucie Diamond.doc .tif [Schreibgeschützt] - Microsoft Office Document Imaging"
Pos:=1
While Pos:=RegExMatch(var,"\.\w{3,}",m,Pos+StrLen(m))
   res := m
MsgBox % res
return

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2010, 5:51 pm 
Code:
string := "Lucie Diamond.doc .jpeg [Schreibgeschützt] - Microsoft Office Document Imaging"
RegExMatch( Flip( string ), "\w{3,}\.", m )
MsgBox, % ext := Flip( m )

Flip(Str) {
   DllCall("msvcrt\_" ( A_IsUnicode ? "wcs" : "str" ) "rev", "UInt",&Str, "CDecl")
   return Str
}
:wink:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 23rd, 2010, 6:01 am 
Offline

Joined: February 11th, 2005, 6:31 am
Posts: 174
Location: Germany
Now that's much more clearer to me. 8) Thank you!


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: rbrtryn and 26 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