AutoHotkey Community

It is currently May 27th, 2012, 11:02 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 43 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: April 17th, 2007, 12:12 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 17th, 2007, 12:28 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Code:
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...

Quote:
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.

_________________
Image


Last edited by majkinetor on April 17th, 2007, 12:38 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 17th, 2007, 12:34 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
majkinetor wrote:
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 17th, 2007, 12:39 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 20th, 2007, 5:07 pm 
Offline

Joined: April 17th, 2005, 7:47 pm
Posts: 289
Location: Sauerland
@toralf
Code:
;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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 20th, 2007, 5:21 pm 
majkinetor wrote:
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...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 20th, 2007, 6:53 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
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...

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 25th, 2007, 9:52 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
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
Code:
  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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2007, 10:31 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 19th, 2008, 3:09 pm 
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)
  • Haystack := "sfsdfsdfabcd"
  • Needle := "^.*+(?<=abcd)"

RegEx Tester reports no match.

However this code
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

pcre man page wrote:
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.


Report this post
Top
  
Reply with quote  
PostPosted: February 21st, 2008, 12:15 pm 
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 wrote:
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)
  • Haystack := "sfsdfsdfabcd"
  • 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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2008, 12:23 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 10th, 2009, 4:36 pm 
Offline

Joined: January 26th, 2009, 5:26 pm
Posts: 151
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 43 posts ]  Go to page Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: iDrug and 60 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group