Sign in to follow this  
Followers 0

String Regular Expression Tester V2

32 posts in this topic




Posted

Since there are WAY to many posts on how to SRE something I thought I would create a nice little tester. ;)

This thing does SRE and SRER.

Loads files to test.

Gets internet content to test.

And more!

Here it is:

Prev DL - 14

Enjoy!

Quick update:

Fixed a few bugs.

Added "Notes" tab

Added "AutoIt" tab.

And thanks for the rate! (Whoever did it) :D

dewittcfez and jewelluoc like this

Share this post


Link to post
Share on other sites

Posted

Sweet!! Now if you can release that bot that will come cram REGEX into my brain!! LOL I just don't get it... :D I can't pull myself out of a wet paper bag using regex... LOL ;)

Share this post


Link to post
Share on other sites

Posted

RegEx isn't that hard to learn. Give yourself 1 hour reading and trying and you can do it.

Mega

Share this post


Link to post
Share on other sites

Posted

Sweet!! Now if you can release that bot that will come cram REGEX into my brain!! LOL I just don't get it... ;) I can't pull myself out of a wet paper bag using regex... LOL ;)

Funny you mention it...

I actually was thinknig about writing a 'bot'.

You supply it the text:

<Xml>Hey</xml>

Highlight it:

<Xml>Hey</xml>

Press the button and you get some options on how it should be formatted.

The problem is, there are alot of options on some pieces of text. Does it look for:

<xml>(.*?)<

>(.*?)<

<(?:.*?)>(.*?)<

<(?:.*?)>(.*?)</

>(.*?)</

...ect...

As you can see with a very simple string there are a lot of different ways to do it. You would have to have some way programmatically to get the result down. Either by supplying it like 5 cases or just testing it with all the results and then testing the list of patterns again with another case. :D

My only other idea was this. Have a button someplace on the GUI that has a nice list of the commands (Currently 'help!'). The commands you could just double click/insert and every command would have an example of how/why it works.

This way would teach the user more than just using the process of elimination. Still don't know if it would be worth all the time in doing...

Share this post


Link to post
Share on other sites

Posted

I am sure I would use it often!

@ Xenobiologist - I have tried, it just does not make sense past the simple examples. For now, I am destined to beg for regex help on the forum.. LOL

Share this post


Link to post
Share on other sites

Posted

Funny you mention it...

I actually was thinknig about writing a 'bot'.

You supply it the text:

<Xml>Hey</xml>

Highlight it:

<Xml>Hey</xml>

Press the button and you get some options on how it should be formatted.

Sounds a little like "Regulazy": http://weblogs.asp.net/rosherove/pages/too...y-osherove.aspx

Share this post


Link to post
Share on other sites

Posted

I downloaded it and will have to sit down with it.. Thanks.. Still waiting for Szhlopp's BOT.. LOL ;)

Meh, that isn't close to the top of my list... :D

May mess with it a little after I put 4.2 out of the olympcs.

Share this post


Link to post
Share on other sites

Posted

Is there any way to add highlighting of matched terms in the text/file view?

Thank you very much, btw, it's saving me a ton of work formatting data for a database ;)

Share this post


Link to post
Share on other sites

Posted

Is there any way to add highlighting of matched terms in the text/file view?

Thank you very much, btw, it's saving me a ton of work formatting data for a database ;)

Welcome.

Highlighting the text found in the text/file tabs?

Hey

Test

1 more word

Pattern: more

'more' lights up?

Interesting... Yeah I might be able to do something like that with a re-work and a good RTF UDF. I may look into this=)

Share this post


Link to post
Share on other sites

Posted

Quick update on the SRE tester.

Added control tips to the radio's.

Fixed an issue with the "Text" tab having a very small limit(Now 1000000).

Added a comment line inside the script to thank w0uter for the original GUI layout.

:P

Share this post


Link to post
Share on other sites

Posted

CONDITIONAL SUBPATTERNS

It is possible to cause the matching process to obey a subpattern conditionally or to choose between two

alternative subpatterns, depending on the result of an assertion, or whether a previous capturingsubpattern

matched or not. The two possible forms of conditional subpattern are

(?(condition)yes-pattern) or (?(condition)yes-pattern|no-pattern)

If the condition is satisfied, the yes-pattern is used; otherwise the no-pattern (if present) is used.

If there are more than two alternatives in the subpattern, a compile-time error occurs.

I was trying this out with your program but could not get anything working.

Is it your program that ignores this or is it AutoIt which does not implement this part of regexp?

Sample input 11:34:26 and 6:48:32 where I want the second to have the 6 zero filled and the seconds removed

From

(\d)?(\d):(\d)?(\d):\d\d
to
(?(1)\1|0)\2:(?(3)\3|0)\4

output is

(?(1)1|0)1:(?(3)3|0)4
(?(1)|0)6:(?(3)4|0)8

but should be
11:34
06:48

Share this post


Link to post
Share on other sites

Posted

I was trying this out with your program but could not get anything working.

Is it your program that ignores this or is it AutoIt which does not implement this part of regexp?

Sample input 11:34:26 and 6:48:32 where I want the second to have the 6 zero filled and the seconds removed

From

(\d)?(\d):(\d)?(\d):\d\d
to
(?(1)\1|0)\2:(?(3)\3|0)\4

output is

(?(1)1|0)1:(?(3)3|0)4
(?(1)|0)6:(?(3)4|0)8

but should be
11:34
06:48
Uhm, I have no idea what you're asking....

All my program does is add a GUI to the AutoIt function "StringRegEx". The version of AutoIt you're using is also the version my script uses(unless you compile it).

Conditional Subpatterns work like this:

Text:

Hello You
Hello Me
Hello Myself

Flag: 3

Pattern:

(?i)Hello\s?(?:You|Me)

(?i) Insensitive flag

"Hello" - Text to find

\s? - Space may or may not appear

(?: - Non capturing group

You|Me - Finds either "You" or "Me"

) - End group

Help explain?

Share this post


Link to post
Share on other sites

Posted

Uhm, I have no idea what you're asking....

If Conditional subpatterns are NOT supported by AutoIt or just your program.

I guess it's AutoIt... or my understanding on how to use them.

Your example had nothing to do with Conditional subpatterns.

Help explain?

I thought I did!

Share this post


Link to post
Share on other sites

Posted

"(\d*:\d*):"

Share this post


Link to post
Share on other sites

Posted

Garp99HasSpoken, AutoIT is using PCRE engine for regex.

PCRE is supporting/implementing conditional subpatterns so there should not be any problem to use them with AutoIT.

But coming back to the GUI proposed by Szhlopp, what it does, is to give you an easy way to test regex without coding script (a bit like RegexBuddy). It helps you to test one regex at time.

Now coming back to your example, I do not understand how it can achieve what you expect in one regex?

Can you explain how you would use it within one regex (only)?

I'm quite new at these regex, but willing to learn.

Thanks.

Best regards.

Share this post


Link to post
Share on other sites

Posted (edited)

Garp99HasSpoken, AutoIT is using PCRE engine for regex.

PCRE is supporting/implementing conditional subpatterns so there should not be any problem to use them with AutoIT.

But coming back to the GUI proposed by Szhlopp, what it does, is to give you an easy way to test regex without coding script (a bit like RegexBuddy). It helps you to test one regex at time.

Now coming back to your example, I do not understand how it can achieve what you expect in one regex?

Can you explain how you would use it within one regex (only)?

I'm quite new at these regex, but willing to learn.

Thanks.

Best regards.

With what he was doing there was no need for a conditional so I just gave him the RegExp in my reply. What that says is; get a digit 0 or more times then the colon then digits 0 or more times again and stop at the next colon. Since none of the characters can be case sensitive I didn't need (?i). It could also heve been written as (?i)(\d*[h:]\d*): which would also allow for those people who have an h as the Hr/Min separator instead of a colon. If it was being used in a StringRegExpReplace situation I would probably use something like (\d*):|h(\d*) as in

$sStr = StringRegExpReplace($sStr, "(\d*):|h(\d*)", "\1:\2") Which would also make sure that the return was 06:48. (Group 1 and colon and group 2)

Edited by GEOSoft

Share this post


Link to post
Share on other sites

Posted

GEOSoft,

I can not make to work any of the example you provide...

Based on your first proposal, some thing like:

$sStr = StringRegExpReplace($sStr, "(\d*:\d*)(:.*)", "\1")

would be closer (to remove seconds), but is still missing the requirement to have a zero filled at the beginning when you have 6:48:32->06:48

In fact, the first regex

(\d)?(\d):(\d)?(\d):\d\d

Garp99HasSpoken was suggesting is ok to match expressions like 11:34:26 and 6:48:32 but that's the second part I would like to understand...

To work it would need to be "run" within the same regex expression (because there are backreferences to group 1,2,3 and 4) but I feel there is a problem with the use of conditional in this case (at least in the way I understand them).

Best regards.

Share this post


Link to post
Share on other sites

Posted

GEOSoft,

I can not make to work any of the example you provide...

Based on your first proposal, some thing like:

$sStr = StringRegExpReplace($sStr, "(\d*:\d*)(:.*)", "\1")

would be closer (to remove seconds), but is still missing the requirement to have a zero filled at the beginning when you have 6:48:32->06:48

The simple explanation for 1 expression is .... you can't.

Share this post


Link to post
Share on other sites

Posted (edited)

The simple explanation for 1 expression is .... you can't.

And that was the whole point of why I was trying to use conditional testing so that I could determine if

the first (optional) digit matched. If it did, then it was a 2-digit hour, if not then I would use 0+second digit

in order to turn it into zero-filled. That's why I used

(\d)?(\d):(\d)?(\d):\d\d

instead of (\d\d) or (\d{2}) which neither helps to indicate how many digits matched.

I saw that as an example in another thread, but for my purposes I was hoping to use it for renaming

TV show files that have S01E01 or s1e01, etc and changed them as 2-digit zero-filled.

What I had to do was use 2 tests

(?i)[ \.]?-?([ \.])S(\d)[ \.]?E(\d+)	  to  \1S0\2E\3
(?i)[ \.]?-?([ \.])S(\d+)[ \.]?E(\d+)	 to  \1S\2E\3

where (?i) is ignore case.

Edited by Garp99HasSpoken

Share this post


Link to post
Share on other sites

Posted

Ok, I see. But I think that conditional testing can only be use to choose an alternative between 2 further matches.

It cannot be used to choose an alternative between 2 string replacement (unfortunately).

Regarding your need to rename TV show files, I suggest you have a look at Renamer which is a very nice program to rename files, using various technics, including Regex ! :P

Best regards.

Share this post


Link to post
Share on other sites

Posted

very useful,

thanks! ^_^

Share this post


Link to post
Share on other sites

Posted (edited)

After speaking with Szhlopp, I'm posting my updated version of the tester. It has a few additions and code cleanup. It's been a while since I updated it, but I think my additions are

- added menu bar

- added keyboard shortcuts (see menus), and Ctrl+A for Select All (not in menu)

- fix for Help button on 64-bit platforms

SRETester.au3

Edited by wraithdu

Share this post


Link to post
Share on other sites

Posted

Thanks for the update! Is it possibe to add a realtime view instead of pushing the Test button first?

Br,

UEZ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0




  • Recently Browsing   0 members

    No registered users viewing this page.