Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

AHK RegEx Tester v2.1


  • Please log in to reply
43 replies to this topic
toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
The more I think of it, I come to the conclusion that it is better to use \n instead of `n, since this is the way PCRE uses it and not a limitation of AHK. To replace `n (or other characters) will introduce more limitations and possible risks of error then it is worth.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
CbbRegEx := RegExReplace(CbbRegEx, "``n", chr(10))
Very nice. I was asking myself can something like this be done in ahk at one moment, but obviously fail to see this solution...

The more I think of it, I come to the conclusion that it is better to use \n instead of `n, since this is the way PCRE uses it and not a limitation of AHK.

What will U use doesn't matter for the user. He must be able to copy/paste RE string from and to AHK source, unchanged. IF you involve elephants from Mars to achieve that, user don't care. He cares only if it works or not and how fast elephants are.

I will check your code at home.
Thx.


PS: I really try to impose a thought in you, about how great this tool can be for general testing of RE. I see that you did it as a side project or something, but it has potential to be really cool, and in absence of some AHK IDE it can come really handy. We are moving toward some nice imporovements on AHK environment. Your SGUI will be superb thing if you finish it, and RE tool can be integrated in it. Also, stdlib is beeing developed by some so we will definitely need some proffesionaly done solutions for AHK development. Thats why I created HexView so it is very flexibile and I implemented all sugestions I received from other users, although I will probably never use some of them. Power developers here should learn to think about greater goal, not just themselves so we can all have something powerful in the near feature. I see this tool as part of such environment.
Posted Image

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005

What will U use doesn't matter for the user. He must be able to copy/paste RE string from and to AHK source, unchanged. IF you involve elephants from Mars to achieve that, user don't care. He cares only if it works or not and about how elephants are fast.

True, to make sure that user can copy the regex to AHK unchnaged it is best to stay with the PCRE syntax. Thus use \n \r \t \R etc.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
But, the user can regulary see `n in other scripts, in manual and around. So he can copy/paste such srcipt from there, then he might want to change it using this tool, just to find out that it doesn't even work, while it worked OK all previous time. So he can deduce that error is in his code and try to fix it , which means loosing a lot of time.

Speaking of that, I don't know why `n is allowed in RE. It should be clean PCRE syntax, without any AHK flavor... some other topic.
Posted Image

Rabiator
  • Members
  • 292 posts
  • Last active: Aug 29 2016 09:29 PM
  • Joined: 17 Apr 2005
@toralf
;requires AHK 1.0.46+
With 1.0.46.00 we get an error inside the loop of Anchor(), I guess due to a bug in the comma separated stuff. Chris fixed it in AHK 1.0.46.01.

__________________________________________
Created with BBCodeWriter 6.6 - the one and only :D

Helpy
  • Guests
  • Last active:
  • Joined: --

Speaking of that, I don't know why `n is allowed in RE.

Because a RE is a plain string, managed by AHK like in any other function call, so regular escapes just work.
But indeed, using classical escapes is the way to go (more universal, less problems with the tester...).
The fact that AHK just allows them in plain strings is even better, in Java you have to write "\\\\UNC\\foo" or "\\d+\\s", which doesn't help in readability...

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006

The fact that AHK just allows them in plain strings is even better, in Java you have to write "\\\\UNC\\foo" or "\\d+\\s", which doesn't help in readability...

right...it was stupid observation from my side anyway...
BTW, that \\...\\\ thing is so anying to me. I usualy write metahcars not like \m but [m]... so I wouldn't write \\\\ but generaly [\][\]... Sed has nice feature to choose your escape char so if it is making your RE looking ugly u can choose what it doesn't.
C# also has something nice for paths. No more "c:\\folder\\foo" but @"c:\folder\foo".

Maybe AHK RE should be updated with new option to match Sed option to escape switch. Like:

\| -> switch \ to |
.. just an idea...
Posted Image

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
I came across a UNIX file where I had to use the `n option for Regex to capture ^ as a new line for multi line haystacks. As majkinetor pointed out this wasn't working. So I had to find a way around it. At least now I had a case to test it with. If you insert these line at line 89 it should work
OP := InStr(CbbRegEx,"(")
  CP := InStr(CbbRegEx,")")
  If (CP AND ( !OP OR CP < OP )){
      RegExMatch(CbbRegEx, "(.*?)(\).*)", Part)           ;split Regex in Options and Regex
      Part1 := RegExReplace(Part1, "``n", chr(10))        ;replace literal `n with a `n character in Regex Options
      Part1 := RegExReplace(Part1, "``r", chr(13))        ;replace literal `r with a `r character in Regex Options
      CbbRegEx := Part1 . Part2
    }
It splits the RegEx into its Options and the regex. And replaces the `n and `r with the 10/13 chr.
I used Instr to determine if there is a Option part, because I couldn't get a regex do it robustly. Maybe someone can point out a nicer way.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
Well... I am not quite sure I understand what happens with new lines in some situations in AHK...

Whewn I get text from edits it requres one setting when I get text from files another, etc...

Maybe somebody can clear out that for us, and I will certanly have a look at your changes.

Code seems to be OK , I doubt it can be much faster considering RE line is very short.
Posted Image

rickly
  • Guests
  • Last active:
  • Joined: --
I find this script very useful for learning and testing
regexs, but I think there may be a bug in AHK RegEx Tester v2.1

Setup: (without quotes)[*:pvkgm50l]Haystack := "sfsdfsdfabcd"
[*:pvkgm50l]Needle := "^.*+(?<=abcd)"RegEx Tester reports no match.

However this code
Haystack := "sfsdfsdfabcd"
Needle := "^.*+(?<=abcd)"
fp := RegExMatch(Haystack,Needle,out)
msgbox, [%fp%]`n[%out%]
reports the match at position 1 with %out% = "sfsdfsdfabcd"% (as expected).

Any chance of getting this fixed (or explained)?

-- rickly

Possessive quantifiers can be used in conjunction with lookbehind
assertions to specify efficient matching at the end of the subject
string. Consider a simple pattern such as

abcd$

when applied to a long string that does not match. Because matching
proceeds from left to right, PCRE will look for each "a" in the subject
and then see if what follows matches the rest of the pattern. If the
pattern is specified as

^.*abcd$

the initial .* matches the entire string at first, but when this fails
(because there is no following "a"), it backtracks to match all but the
last character, then all but the last two characters, and so on. Once
again the search for "a" covers the entire string, from right to left,
so we are no better off. However, if the pattern is written as

^.*+(?<=abcd)

there can be no backtracking for the .*+ item; it can match only the
entire string. The subsequent lookbehind assertion does a single test
on the last four characters. If it fails, the match fails immediately.
For long strings, this approach makes a significant difference to the
processing time.



rickly
  • Guests
  • Last active:
  • Joined: --
Well, I cant explain it, but it appears that RegEx Tester is now returning
the correct results. :oops:

Believe it or not, I very carefully checked everything before posting to be sure I did not make a fool of myself - but it looks like I did anyway! Maybe I had a space (or other non-printing char) appended to the Needle. Who knows? - but all is working now. :!:

I find this script very useful for learning and testing
regexs, but I think there may be a bug in AHK RegEx Tester v2.1

Setup: (without quotes)[*:2vbp0dc0]Haystack := "sfsdfsdfabcd"
[*:2vbp0dc0]Needle := "^.*+(?<=abcd)"RegEx Tester reports no match.


Moderator - feel free to delete my two posts here.
Also, this is such a useful script that you should consider making it
"sticky". I have been working my way though the pcre man page, and
this script has really helped in understanding re's.

toralf not loged in
  • Guests
  • Last active:
  • Joined: --
Hi rickly,

Thanks for the feedback. I'll not remove your posts, since they are a good example of the scripts possibilities/features. Thank you that you have found it to be working. I didn't had the time to check it out myself.

Happy scripting

LiquidGravity
  • Members
  • 156 posts
  • Last active: Oct 11 2014 04:11 PM
  • Joined: 26 Jan 2009
I'd suggest a button be added to send the entire performed string to the clipboard in RegExMatch( or RegExReplace( format depending on the tab and things selected. Makes it much quicker.

AhkLearner
  • Members
  • 101 posts
  • Last active: Aug 27 2016 12:58 PM
  • Joined: 25 Feb 2014

can somebody post some examples to test with!