 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Superfraggle
Joined: 02 Nov 2004 Posts: 773 Location: London, UK
|
Posted: Fri Jun 15, 2007 7:57 am Post subject: Problem with regexmatch output |
|
|
I have a problem with my regular expression, I am new to the whole regex thing, but I must of read at least 3 tutorials now, and think I understand the principles.
However I am getting completely thrown by what is happening here. Could someone please attempt to explain this to me.
| Code: |
ref:="1-1139732532"
regexmatch(ref,"(1-\d{9,10})",ref)
|
Will produce a match (as it should)
and set the following vars
ref[12 of 63]: 1-1139732532
ref1[12 of 63]: 1-1139732532
So far so good, however
| Code: |
ref:="5641-1139732532"
regexmatch(ref,"(1-\d{9,10})",ref)
|
No difference there except there are a few numbers in front of the original number.
We still get a match so the regex is able to correctly identify the pattern.
However now the outputted vars are ref[12 of 63]: 1-1139732532
ref1[12 of 63]: 39732532
Notice the second var has changed, why is this?
It is my understanding that the second var (ref1) should be the first pattern match, which seeing as the whole thing is in brackets should be the whole thing.
Strangly enough as well if i had one extra number I lose one number of the start of ref1 add 2 i lose 2 so the following pattern emerges.
original=1-1139732532 >>>>>>ref1=1-1139732532
original=11-1139732532>>>>>>ref1=-1139732532
original=111-1139732532 >>>>>>ref1=1139732532
original=1111-1139732532>>>>>>ref1=139732532
original=11111-1139732532>>>>>>ref1=39732532
This carries on until we reach
1111111111111-1139732532 which makes ref1 return nothing
After this point however, add as many more numbers and/or letters to the beginning as you want but ref1 will always produce the same as ref.
I hope that explains it enough, now can someone please explain that to me. _________________ Steve F AKA Superfraggle
http://r.yuwie.com/superfraggle |
|
| Back to top |
|
 |
YMP
Joined: 23 Dec 2006 Posts: 265 Location: Russia
|
Posted: Fri Jun 15, 2007 10:40 am Post subject: |
|
|
This seems to work normally. I changed the name of the output var to make it different from the input.
| Code: |
ref:="5641-1139732532"
regexmatch(ref,"(1-\d{9,10})", res)
Msgbox, res=%res%`nres1=%res1%
|
|
|
| Back to top |
|
 |
Superfraggle
Joined: 02 Nov 2004 Posts: 773 Location: London, UK
|
Posted: Fri Jun 15, 2007 10:50 am Post subject: |
|
|
Ok so it doesn't like the input and output var being the same name. Strange how some of it works and others don't.
So is this a bug, or should input and output never be the same?
I couldn't see this in the documentation, although I keep missing things like that. _________________ Steve F AKA Superfraggle
http://r.yuwie.com/superfraggle |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Fri Jun 15, 2007 11:04 am Post subject: |
|
|
It baffles me as well, so I revived my old PCRE wrapper script and tested the expression against PCRE 6.4. Here, both the global capture and the first one are identical.
So it looks like a real bug, hopefully in AHK, not in PCRE...
Unless Chris has a better explanation. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5026 Location: imaginationland
|
Posted: Fri Jun 15, 2007 12:01 pm Post subject: |
|
|
I suspect it's a bug with the way AutoHotkey parses the result, because extracting them yourself in position and length mode works:
| Code: | seq = 5641-1139732532
matchPos := RegExMatch(seq, "P)(1-\d{9,10})", match)
StringMid, ref, seq, matchPos, match
StringMid, ref1, seq, matchPos1, matchLen1
MsgBox, %ref%`n%ref1% |
_________________
RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Fri Jun 15, 2007 1:40 pm Post subject: |
|
|
| YMP wrote: | | I changed the name of the output var to make it different from the input. | Oh, I totally missed this one... So it might be an AHK bug in handling variables (overwriting?). _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Wed Nov 21, 2007 2:54 pm Post subject: |
|
|
| This issue has hopefully been fixed in today's v1.0.47.05. Thanks for reporting it. |
|
| 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
|