AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

RegEx Faster? Easier? - SOLVED

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
StreetRider



Joined: 19 Mar 2008
Posts: 73
Location: Euclid, Ohio

PostPosted: Sun May 11, 2008 4:29 pm    Post subject: RegEx Faster? Easier? - SOLVED Reply with quote

I can not seem to get my arms around RegEx. From what I understand it is probably faster and easier for this type of operation.

This is how I understand to do this the old BASIC method.

UPDATE: This code is a sample of code that is part of a parsing program that edits CNC fanuc code. There is a x value in the last line of code that I need to extract, make metric(*25.4) and save in a var that I can insert else where in the file. I have gotten everything to work, but the cod e is long and clumbsy. Can anyone help with maybe a RexEx usage. I plan on using this example to help explain the use to myself as well as us in my finish program.

Function: Look at the two variables. If %LastLine% has x it use it. If %LastLine% aslo contains y trim out x only.

Code:


StlLine= x1.2345 y12.123
LastLine= g01 y1.234

PullBack:= LastLine

IFNotInString , LastLine, x
   PullBack:= StlLine

IfInString, PullBack, Y
   Gosub TrimIT
MsgBox, %PullBack%
return

TrimIt:

StringGetpos, Y, PullBack, y
;Y:= InStr(PullBack, y)
MsgBox, %Y%
StringGetPos, X, PullBack, X
;X:= Instr(PullBack, X)
MsgBox, %X%
;StringLeft
StringMid, PullBack, PullBack, x, y - x   
Return




It seems to do what I need, but I bet there is a better way.. Smarter way?
Code:

StlLine= x1.2345 y12.123
LastLine= g01 y1.234

PullBack:= LastLine

IFNotInString , LastLine, x
   PullBack:= StlLine

IfInString, PullBack, Y
   Gosub TrimIT
MsgBox, %PullBack%
return

TrimIt:

RegExMatch(PullBack, "(?<=\bx)[+\-]*\d+(?:\.\d+)?(?=\s|$)", PullBack)
Return




_________________
StreetRider
Euclid. Ohio

"New and Loving it!"


Last edited by StreetRider on Mon May 12, 2008 1:01 pm; edited 3 times in total
Back to top
View user's profile Send private message
Oberon



Joined: 18 Feb 2008
Posts: 408

PostPosted: Sun May 11, 2008 4:40 pm    Post subject: Reply with quote

Sorry I failed to understand your description and objectives, your choice of variable names didn't help either (PullBack??). Anyway if you want to extract only a certain word from a string regex can help:

Code:
var = x1.2345 y12.123
RegExMatch(var, "\bx.+?(?=\s|$)", var)
MsgBox, %var% ; gives: x1.2345

_________________
Back to top
View user's profile Send private message
StreetRider



Joined: 19 Mar 2008
Posts: 73
Location: Euclid, Ohio

PostPosted: Sun May 11, 2008 4:51 pm    Post subject: Thank you once again Oberon. Reply with quote

Well, the varialble labels would make sense if you were wrtiing the code for parsing a CNC fanuc file.

But your line of code does return what I need.

Well, almost. How about just the number so that I could perform math on the value and return it to my file at another point.

Also, Oberson. Are you having a bad day? You answered my question so beautifully that you must ahve understood my gibberish.

Thank you again. And have a GREAT DAY!
_________________
StreetRider
Euclid. Ohio

"New and Loving it!"
Back to top
View user's profile Send private message
Oberon



Joined: 18 Feb 2008
Posts: 408

PostPosted: Sun May 11, 2008 5:33 pm    Post subject: Re: Thank you once again Oberon. Reply with quote

StreetRider wrote:
How about just the number so that I could perform math on the value and return it to my file at another point.
Change the expression to: (?<=\bx)[+\-]*\d+(?:\.\d+)?(?=\s|$)
_________________
Back to top
View user's profile Send private message
Guest






PostPosted: Sun May 11, 2008 6:27 pm    Post subject: Reply with quote

you really need this

http://gskinner.com/RegExr/
Back to top
Krogdor



Joined: 18 Apr 2008
Posts: 23

PostPosted: Sun May 11, 2008 9:57 pm    Post subject: Reply with quote

I know this is off topic but...

To whoever that Guest is,

I love you.
That site = <33333

I can barely comprehend the simplest of RegEx's, despite an online tutorial I've been looking through, and that site is just plain awesome.

Thank you Very Happy
Back to top
View user's profile Send private message
NLI-Conquer
Guest





PostPosted: Mon May 12, 2008 12:58 am    Post subject: Reply with quote

Krogdor:

Its always a good idea to edit your main post and put [Solved] in the thread title once its solved, so when users are searching for their answers (even though I swear 80% of the forum doesn't know the Search button is there), they will know that the thread is solved.

Thx for listening. Wink
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group