Sign in to follow this  
Followers 0
DoubleMcLovin

Regex Help

12 posts in this topic

I am looking for a regex pattern that will match "bobby.01.yaddy.yaddy.0101010.avi" but not match "example.101.02.The.example.Returns.Part.1.2.Moonsong.avi" by looking at the digits. It needs to match exactly 2 characters and keep the surrounding text using a pattern similar to

(?i)(.+)\.(\d{2})\.?(.*)(\..+)\b

It needs to be able to "see" that there are exactly two digits inside a decimal and they are not directly followed by a possible decimal (\.?) and then more digits up to 4 (\d{1,4}) but I cannot get the negative lookaround to match without excluding all matches. Sorry if this is a bit confusing.

Share this post


Link to post
Share on other sites



DoubleMcLovin,

exactly two digits inside a decimal and they are not directly followed by a possible decimal and then more digits up to 4

Try this - it works on your 2 examples: ;)

(\.\d{2}\.)(?!\d{1,4})

(\.\d{2}\.) - look for "point - 2 digits - point"

(?!\d{4}) - not followed by "1 to 4 digits"

Any good? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

It is a bit confusing but this might be what you are looking for

#include<array.au3>;; For displaying results only
$sStr = "bobby.01.yaddy.yaddy.0101010.avi" & @CRLF
$sStr &= "example.101.02.The.example.Returns.Part.1.2.Moonsong.avi"

$aMatches = StringRegExp($sStr, "([a-z]+\.\d{2}[.\D].+)", 3)
If NOT @Error Then
    _ArrayDisplay($aMatches)
Else
    MsgBox(4096, "Error", "No matches to the pattern")
EndIf

When posting for an SRE response please put your examples on separate lines in the post. It makes it much easier to see what you are doing that way. In this case, if I read it correctly, it should have been like this for readability

Match

bobby.01.yaddy.yaddy.0101010.avi

Don't Match

example.101.02.The.example.Returns.Part.1.2.Moonsong.avi


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Sorry, I should have been more specific about those dots. This is to help sort my personal media files, the format of each file is different but in general follows the scheme:

"showName.season#.ep#.episodeTitle.ext"

The regex is broken into parts, this part is to catch when there is no 'season#' present. The trouble is, sometimes (assume randomly) 'episodeTitle' does not exist either. So the string could be either "showName.ep#.episodeTitle.ext" or "showName.ep#.ext". We need this StringRegExp() to capture into an array

[1]showName

[2]ep#

[3](possible)episodeTitle

[4].ext

So my idea using your example is:

(?i)(.+)\.(\d{2})\.?(?!(\d{1,4}))\.?(.*)(\..+)\b

This doesn't work when I run it through the regex tester since it captures all the sample strings =\

Share this post


Link to post
Share on other sites

@M23

You are getting much faster at replying to SRE topics. Good to see.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

George,

Only way to learn is to try! :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

M23,

Try and try and yet try again ... and hence to loose hair faster (look at George's head...) :)


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Now I'm getting French insults too when the Aussie ones were enough. I pulled all my hair out just from being on these forums for too long.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Yeah, you're right: responsabilities are more probably 80% forum 20% PCRE.

BTW I didn't drop work on PCRE but keep being distracting by last year' emergencies.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

I hope you don't drop that project. It can be important. I had a couple of things I was going to ask about in a PM but I forgot what they were. Next we have Valik coming along with "bald AND senile".


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Here is the string I came up with to match this the way I need to. It looks ugly, but gets the job done.

(?i)(?=(?:\b\D*\d{2}\D{2}.*\b))(.+)\.(\d{2}(?!(?:\d+|.*\d+\D+\d+)))\.?(.*)(\..+)\b

Share this post


Link to post
Share on other sites

Whatever works. You don't need the (?i) since you are not using litteral characters in the expression.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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