AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 789 posts ]  Go to page Previous  1 ... 22, 23, 24, 25, 26, 27, 28 ... 53  Next
Author Message
 Post subject:
PostPosted: April 15th, 2010, 6:46 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Quote:
I'm sure it's some obvious facet of InputBox that I'm overlooking ... ; enter `r`n`r`n
Yeah, have you tried sending that to the InputBox? :wink:
Code:
^w:: Send, `r`n`r`n

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject: why a right ) in a RegEx
PostPosted: June 17th, 2010, 5:26 pm 
Offline

Joined: January 20th, 2007, 7:47 pm
Posts: 110
sinkfaze was kind enough to help me elsewhere (I hadn't discovered this topic yet). Now I'm trying to understand more, and one of the scripts he gave me was...
var := RegExReplace(var,"`nm)^\s+") ; removes leading spaces from any line.

what does the ) after the m do? evidently it doesn't have to be paired with a ( so it must have some specific function. I've thumbed through various cheatsheets and don't see it mentioned. THANKS

_________________
...Ed


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 17th, 2010, 5:30 pm 
Offline

Joined: July 30th, 2007, 11:32 pm
Posts: 581
EdScriptNewbie wrote:
sinkfaze was kind enough to help me elsewhere (I hadn't discovered this topic yet). Now I'm trying to understand more, and one of the scripts he gave me was...
var := RegExReplace(var,"`nm)^\s+") ; removes leading spaces from any line.

what does the ) after the m do? evidently it doesn't have to be paired with a ( so it must have some specific function. I've thumbed through various cheatsheets and don't see it mentioned. THANKS


Check out the Options section of RegExMatch (they're the same for RegExReplace). You'll find the explanations for the `n and the m options there.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 17th, 2010, 5:34 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
At the very beginning of a regular expression, specify zero or more of the following options followed by a close-parenthesis. For example, the pattern "im)abc" would search for abc with the case-insensitive and multiline options (the parenthesis may be omitted when there are no options).

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 17th, 2010, 6:09 pm 
Offline

Joined: January 20th, 2007, 7:47 pm
Posts: 110
ah! (& duh) Thanks guys.

_________________
...Ed


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 10th, 2010, 9:50 pm 
Offline

Joined: March 9th, 2007, 2:47 am
Posts: 509
Location: Unknown
Code:
FileRead, string, temp.txt
RegExMatch(string, "{""season"": " . 4 . ", ""name"": ""\K.*(?="", ""number"": " . 3 . "})", output)
msgbox %output%


And here is temp.txt
Code:
{"season": 4, "name": "Fast Friends", "number": 2}, {"season": 4, "name": "Made Man", "number": 3}

I am trying to get the output to be "Made Man" (without quotes) but it only seems to workwhen the string is just the part in the regex (just "{"season": 4, "name": "Made Man", "number": 3}").

edit:
This does not work either
Code:
FileRead, string, temp.txt
RegExMatch(string, "(?<={""season"": 4, ""name"": "")\K.*(?="", ""number"": " . 3 . "})", output)
msgbox %output%


edit2:
figured it out. this tool is amazing http://www.gethifi.com/tools/regex#
Code:
RegExMatch(string, "(?<={""season"": 4, ""name"": "")[^""]*(?="", ""number"": " . 3 . "})", output)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 10th, 2010, 10:38 pm 
System Monitor wrote:
edit2:
figured it out.

...ugh, look what you made me write/test...

Code:
#SingleInstance force
#Persistent

string={"season": 4, "name": "Fast Friends", "number": 2}, {"season": 4, "name": "Made Man", "number": 3}

regex={"season": 4, "name": "(?<name>[^"]*)"

p:=1
Loop {
   ret1:=RegExMatch(string, regex, m, p)
   if (ret1=0) {
      break
   }
   el1:=errorlevel, le1:=A_LastError
   ret2:=RegExMatch(string, "P)" regex, p, p)
   el2:=errorlevel, le2:=A_LastError
   p:=pposname
   msgbox, 64, , p(%p%)`nret1(%ret1%) el1(%el1%) le1(%le1%)`nret2(%ret2%) el2(%el2%) le2(%le2%)`n`ns(%string%)`n`nm(%m%)`n`nmname(%mname%)`n`nm1(%m1%)`nm2(%m2%)
}

...anyway, mine loops thru & returns each name in an mname var. Also, by putting the regex in a var you avoid needing to escape/double up the double quotes! BTW, what is the \K for in your orig regex, seems to be invalid for AutoHotkey. & is there a reason you want to match Made Man & not match Fast Friends 1st?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 28th, 2010, 5:42 pm 
Offline

Joined: March 18th, 2009, 3:06 pm
Posts: 17
Location: Minnesota, USA
I'd like to remove any line that contains NMError. I've tried a bunch of regexes, but can't seem to get it to match correctly. In this case, the INSERT Win32_FloppyDrive line.

Thanks,
Pete

Code:

StrOut=
(
DELETE FROM tblWin32_PhysicalMemory WHERE Node = "MAINXP";
INSERT INTO tblWin32_PhysicalMemory(Node,BankLabel,Capacity,DataWidth,DeviceLocator,Speed)VALUES ( 'MAINXP', 'Bank0/1', '2147483648', '64', 'A0', '800');
INSERT INTO tblWin32_PhysicalMemory(Node,BankLabel,Capacity,DataWidth,DeviceLocator,Speed)VALUES ( 'MAINXP', 'Bank2/3', '2147483648', '64', 'A1', '800');
DELETE FROM tblWin32_VideoController WHERE Node = "MAINXP";
INSERT INTO tblWin32_VideoController(Node,AdapterRAM,CurrentBitsPerPixel,CurrentHorizontalResolution,CurrentRefreshRate,CurrentVerticalResolution,Description,DriverDate,DriverVersion)VALUES ( 'MAINXP', '1073741824', '32', '1920', '60', '1200', 'NVIDIA GeForce 9600 GT', '20100112040333.000000-000', '6.14.11.9621');
DELETE FROM tblWIN32_FloppyDrive WHERE Node = "MAINXP";
INSERT INTO tblWIN32_FloppyDrive(Node,Description,Name)VALUES ( 'MAINXPNMError - No Instance - WIN32_FloppyDrive');
DELETE FROM tblWin32_SoundDevice WHERE Node = "MAINXP";
INSERT INTO tblWin32_SoundDevice(Node,Manufacturer,Name)VALUES ( 'MAINXP', 'Realtek', 'Realtek High Definition Audio');
)

  StrOut := RegExReplace(StrOut, "NMError.*?;(?<=INSERT)", "")
  MsgBox, %StrOut%
  ExitApp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 28th, 2010, 11:52 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Do you necessarily need RegEx for this?

Code:
StrOut=
(
DELETE FROM tblWin32_PhysicalMemory WHERE Node = "MAINXP";
INSERT INTO tblWin32_PhysicalMemory(Node,BankLabel,Capacity,DataWidth,DeviceLocator,Speed)VALUES ( 'MAINXP', 'Bank0/1', '2147483648', '64', 'A0', '800');
INSERT INTO tblWin32_PhysicalMemory(Node,BankLabel,Capacity,DataWidth,DeviceLocator,Speed)VALUES ( 'MAINXP', 'Bank2/3', '2147483648', '64', 'A1', '800');
DELETE FROM tblWin32_VideoController WHERE Node = "MAINXP";
INSERT INTO tblWin32_VideoController(Node,AdapterRAM,CurrentBitsPerPixel,CurrentHorizontalResolution,CurrentRefreshRate,CurrentVerticalResolution,Description,DriverDate,DriverVersion)VALUES ( 'MAINXP', '1073741824', '32', '1920', '60', '1200', 'NVIDIA GeForce 9600 GT', '20100112040333.000000-000', '6.14.11.9621');
DELETE FROM tblWIN32_FloppyDrive WHERE Node = "MAINXP";
INSERT INTO tblWIN32_FloppyDrive(Node,Description,Name)VALUES ( 'MAINXPNMError - No Instance - WIN32_FloppyDrive');
DELETE FROM tblWin32_SoundDevice WHERE Node = "MAINXP";
INSERT INTO tblWin32_SoundDevice(Node,Manufacturer,Name)VALUES ( 'MAINXP', 'Realtek', 'Realtek High Definition Audio');
)

Loop, parse, StrOut, `n, `r
   if   InStr(A_LoopField,"NMError")
      continue
   else   res .=   ((A_Index=1) ? "" : "`n") A_LoopField
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: July 29th, 2010, 3:52 pm 
Offline

Joined: March 18th, 2009, 3:06 pm
Posts: 17
Location: Minnesota, USA
Thanks sinkfaze, that worked great. I appreciate it. :)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: August 19th, 2010, 1:01 pm 
Offline

Joined: May 19th, 2007, 4:15 pm
Posts: 5
Hi Guys,

im not familiar with programming and regular expressions. For 3 days i am reading through the topics here in this forum.
But unfortunately i am not that skillful to solve my issue.
Maybe somebody can help?


That is the copied content of the clipboard. It is the starting point of my Request:
Quote:
n2100355.tfg.intern.org
m1001355.355.intern.org
m1101355.355.intern.org
n2020355.tfg.intern.org
n0058355.tfg.intern.org
c2001355.355.intern.org
c2002355.355.intern.org
w0249355.355.intern.org
r0100355i01.355.intern.org
r0000355i02.355.intern.org
r0000355i03.355.intern.org
w0500355.355.intern.org


I only need the alpha numeric numbers till the first period(first stop). Afterwards the period should be exchanged by a semicolon. All the numbers can vary from 0-9. There are up to 200 lines possible.
The Output should look like that way:
Quote:
n2100355;
m1001355;
m1101355;
n2020355;
n0058355;
c2001355;
c2002355;
w0249355;
r0100355i01;
r0000355i02;
r0000355i03;
w0500355;


I use this AHK Scriptcode:
Code:
^!v::
Input := Clipboard
StringReplace, Input, Input, ;; ...
Clipboard := Input
Send ^v
return


I thought Stringreplace should work but i have problems to get the position of the first period to cut off the second half of the whole string.
Maybe you can help me with my tiny request.


Kindest Regards
Kulturbanause


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2010, 1:08 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
You can use regex but you can always start by using simple commands like substr and instr. Simply parse the clipboard line by line. Lookup the SubStr and InStr commands in the doc you should be able to understand what the loop below does.

Code:
Clipboard=
(
n2100355.tfg.intern.org
m1001355.355.intern.org
m1101355.355.intern.org
n2020355.tfg.intern.org
n0058355.tfg.intern.org
c2001355.355.intern.org
c2002355.355.intern.org
w0249355.355.intern.org
r0100355i01.355.intern.org
r0000355i02.355.intern.org
r0000355i03.355.intern.org
w0500355.355.intern.org
)

Loop, Parse, Clipboard, `n, `r
    OutPut .= SubStr(A_LoopField, 1, InStr(A_LoopField, ".")-1) . ";`n"
MsgBox % Output   

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2010, 1:38 pm 
Offline

Joined: May 19th, 2007, 4:15 pm
Posts: 5
Hi!,

thx for the fast reply. The clipboard content is always dynamic. Is there a way to solve that in your code?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2010, 1:47 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Yes, clipboard is a variable known to AutoHotkey, so remove the clipboard= lines and assign the loop code to a hotkey, replace the msgbox with clipboard:=output. If you don't understand any of what I just said, start with the tutorials http://www.autohotkey.com/wiki/index.ph ... #Tutorials because it is very basic.

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2010, 2:18 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
I think this will work:

Code:
Clipboard=
(
n2100355.tfg.intern.org
m1001355.355.intern.org
m1101355.355.intern.org
n2020355.tfg.intern.org
n0058355.tfg.intern.org
c2001355.355.intern.org
c2002355.355.intern.org
w0249355.355.intern.org
r0100355i01.355.intern.org
r0000355i02.355.intern.org
r0000355i03.355.intern.org
w0500355.355.intern.org
)
MsgBox %   RegExReplace(Clipboard,"im`n)^[^\.]+\K.*",";")   
return

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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 789 posts ]  Go to page Previous  1 ... 22, 23, 24, 25, 26, 27, 28 ... 53  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: bobbysoon, Yahoo [Bot] and 21 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