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
majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
Thx toralf. Thats what it missed.
Posted Image

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
I'd +Theme the Tab control and +BackgroundTrans all child Texts to make the GUI look prettier. Also with an expression like (?P<e>(?<=(?P<q>[ax]))b|c) for the string "abbxcacbc" the q subpattern is not detected, so you'll need to recurse into every set and not only the capturing ones.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


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

first post got updated:

2.1)
- subpattern can be encapsulated (thanks titan)
- tab with text fields allow theme (thanks titan)
- a small fix for the layout of the result


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
There seem to be a bug with multiline expressions.

In my ahk regex work I concluded that the problem is that sometimes new line should be threated as `n and sometimes as `r`n.

So here, depending on input, I use `nm) or just m)
I can't figure out how to compile any multiline regexp. I also tried \n with same results.

BTW, Why don't you change a little your interface so to use different fonts. Larger and for RE edit with fixed pitch. I already did so here, as I wasn't able to see reg ex clearly.

It would also be great to allow naming of RE's before saving. BUnch of RE's without a name is garbage to me.
Posted Image

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

There seem to be a bug with multiline expressions.

In my ahk regex work I concluded that the problem is that sometimes new line should be threated as `n and sometimes as `r`n.

So here, depending on input, I use `nm) or just m)
I can't figure out how to compile any multiline regexp. I also tried \n with same results.

Do you thing this is a AHK problem, or of my GUI? Could you please give an example?

BTW, Why don't you change a little your interface so to use different fonts. Larger and for RE edit with fixed pitch. I already did so here, as I wasn't able to see reg ex clearly.

Could you please provide some example code? I think that would make it easier for me to understand your request.

It would also be great to allow naming of RE's before saving. BUnch of RE's without a name is garbage to me.

The aim of this GUI is to help to get a RegEx testing fast. To add names for regex, would require to open a inputbox to ask for the name, and to change the combobox handling. If users (like me) do not want to give names, it requires an option to be set/stored and retrieved. This all sums up to quite a lot of code, which I do not see the need currently. But I will take a note and if there are other requests that will allow this to be add easily too I'll do it. Thanks for the suggestion.
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
Listen, toralf, I don't know how did you envision your tool, but it may be great for serious RE testing, especialy in AHK as it uses its syntax for some things.


Do you thing this is a AHK problem, or of my GUI? Could you please give an example?

Your GUI.
This works in AHK (see HexView if you like)
hexa := RegExReplace( hexa, "`nm)[ ]$")

but not in your GUI. I also tried with \n

Could you please provide some example code? I think that would make it easier for me to understand your request.

Yup.
Try this :D
Gui, 1:Font, s12
Then extrapolate. REG EX Edit is the point of your GUI, so it must be large, with some coding font like Courier New so you can clearly see each char etc... Perfectly, you will hae some ini options for this. GUI Setup is not required, U can just use some ini options and document them, like
[FONTS]
Re=s12, Courier New
Haystack=s10
Result=s8, Arial
Gui=s10;  eventualy

although I find just Re font to be extremely important others you can eventualy skip.

The aim of this GUI is to help to get a RegEx testing fast. To add names for regex, would require to open a inputbox to ask for the name, and to change the combobox handling.

Yup, but if you update your RE a lot, over time, you enter/exit helper several times. You think your RE is ok, then you exit, then you find out its not after some time, then you get back, then you have bunch of your REs that you don't know which to choose. Limitation about 10 RE's is also not nice.

Then, about input box and combo box that is trivial change in the code, 10 lines at most. You can have option in ini if to ask for RE name or not, or have another button that will save the regex. IMO, the best solution would be to use hidden ListView with columns Name|RE. Once user clicks the > arrow of combo or you can remove combo, put edit with the button aside to make it easier, you show listview bellow the edit. Upon selection you hide it. IF you do so, you can connect this with ini option about naming, so you can make name column be size 0 in case user=toralf.

Speaking about buttons, most of them are useless just taking up space.


Keybaord|Mouse

Close - Esc | x
CopyRegEx - Ctrl+Home Ctrl+C | select, rmb, copy

StoreRegEx - U can use CTRL ENTER| smaller button next to the combo is better choice.


This is what I find anoying about otherwise excellent tool for RE building, which I prefer more then anything else I saw around. Just a little more effort is needed to make this good both for quick and heavy usage.
Posted Image

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
`nm)[ ]$
will not work in the edit field, since it will be seen as new line when the gui gets submit. Have you tried:
``nm)[ ]$
?
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
No, I didn't.

It still is a bug. I, as a user, need guarantie that the RE I get can be used unchanced in AHK and vice-versa.

I see that you did not welcome further suggestions.
Sorry, I guess I misunderstood domain of your app.
Posted Image

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Regrading the "bug": I currently do not see how I could fix this. Could you give me a hand?

I see that you did not welcome further suggestions.
Sorry, I guess I misunderstood domain of your app.

What made you think this?
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

Regrading the "bug": I currently do not see how I could fix this. Could you give me a hand?

I'll see what I can do.

What made you think this?

Silence.
Posted Image

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
OK, I checked out what you can do.

As you will get `n as plain charachters you must conver them to binary `n.

So, if i write
line1`nline2

You will get variable containing this data:

6C 69 6E 65   31 [color=brown]60 6E [/color]6C   69 6E 65 32   | line1[color=brown]`n[/color]line2

While it should contain this data:
6C 69 6E 65   31 [color=green]0A[/color] 6C 69   6E 65 32 | line1[color=green].[/color]line2

To make first become the second, you should split it by `n string in a loop and concatenate strings that `n delimits with binary `n:

s1 := string before "`n" string
    s2 := string after "`n" string
    s := s1 "`n" s2
then, you use s as Regular Expression.

What is funny is that \n works fine, but not if i put it as an option, where it apperently requires `n. This appears to be AHK incosistency, or even bug.
Posted Image

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Thanks a lot for your help.
Could you please provide a haystack, regex and result I could test it with, then I can update the code.

Last night I though of it and wanted to test if I could use RegExReplace to do the modification. When I have your example I will test this too.
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.

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

What is funny is that \n works fine, but not if i put it as an option, where it apperently requires `n. This appears to be AHK incosistency, or even bug.

I do not know if Chris watches this thread, so you might want to post this behaviour in the bug section.
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 was using simple things for the start:

Haystack:
line1
line2
line3
line4

Replace RE: line1`nline2

About `n) option I am not sure if I understand where you must use it where not, but that is not improtant as long as RE is redirected to RegEx functions the same as I would type in the code. So if you make above work fine, every `n occurance will be treated the same.

Pseudo code is something like:

ControlGet, reToFix, , editRE
   j := 0, k = 0
   loop {
       StringGetPos, k, reToFix, `n, j+1
       if (k = -1) 
               re .= RemainingLinePart
               break
       else
               StringMid, BeforeN reToFix, j+1, k....
               re .=  BeforeN "`n"
  }

or

StringReplace, reToFix, `n,  1/4  (some symbol unlikely to be used)
   Stringsplit, out, reToFix, 1/4
   loop, %outNum%
         re .= out%A_LoopField%

Posted Image

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Could you please add at line 87 this line
CbbRegEx := RegExReplace(CbbRegEx, "``n", chr(10))
and tell me if that fixes the problem?

It is here:
EvaluateRegEx:
  If UpdateComboBox
      Return
  Gui, 1:Submit, NoHide                       
  If (!CbbRegEx OR !EdtHaystack){   
      GuiControl, 1:, EdtResult,                         
      Return                                               
    }
  CbbRegEx := RegExReplace(CbbRegEx, "``n", chr(10))   ;<==== here
  If (TabRegExType = "Match") {                    

Thanks a lot
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.