 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
StreetRider
Joined: 19 Mar 2008 Posts: 73 Location: Euclid, Ohio
|
Posted: Sun May 11, 2008 4:29 pm Post subject: RegEx Faster? Easier? - SOLVED |
|
|
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 |
|
 |
Oberon
Joined: 18 Feb 2008 Posts: 408
|
Posted: Sun May 11, 2008 4:40 pm Post subject: |
|
|
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 |
|
 |
StreetRider
Joined: 19 Mar 2008 Posts: 73 Location: Euclid, Ohio
|
Posted: Sun May 11, 2008 4:51 pm Post subject: Thank you once again Oberon. |
|
|
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 |
|
 |
Oberon
Joined: 18 Feb 2008 Posts: 408
|
Posted: Sun May 11, 2008 5:33 pm Post subject: Re: Thank you once again Oberon. |
|
|
| 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 |
|
 |
Guest
|
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 23
|
Posted: Sun May 11, 2008 9:57 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
NLI-Conquer Guest
|
Posted: Mon May 12, 2008 12:58 am Post subject: |
|
|
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.  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|