Terenz Posted March 14, 2020 Share Posted March 14, 2020 Hello, I need to match in regex if a filename have month and year. Example my_business_03_2020 03 my business 2020 And so on. So i need to match if there are two digit consecutive and four digit consecutive and extract from the file name. I need both, if exist one of the two is considerated "error" for me Thanks Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
ahmet Posted March 14, 2020 Share Posted March 14, 2020 (edited) Can this help $sTestString="my_business_032020" $btest=StringRegExp($sTestString,".*\d\d.*\d\d\d\d") MsgBox(0,"Test",($btest ? "There is" : "There is not") & " date") You can look at regex101.com for explanation Edited March 14, 2020 by ahmet Terenz 1 Link to comment Share on other sites More sharing options...
Terenz Posted March 14, 2020 Author Share Posted March 14, 2020 (edited) Hi ahmet. Thanks for your help I need to get the month and the date from the file [0]=03 [1]=2020 I have try to change the RegEx flag to 3 but not work, return all the string Edited March 14, 2020 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
Marc Posted March 14, 2020 Share Posted March 14, 2020 $sTestString="my_business_032020" $btest=StringRegExp($sTestString,".*(\d\d).*(\d\d\d\d)",1) if IsArray($btest) Then $month = $btest[0] $year = $btest[1] MsgBox(0,"Test", "Month: " & $month & @CRLF & "Year: " & $year) Else ; error EndIf Based on the example from ahmet Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL) Link to comment Share on other sites More sharing options...
Nine Posted March 14, 2020 Share Posted March 14, 2020 Maybe this ? #include <Constants.au3> #include <Array.au3> Local $aTxt = ["my_business_03_2020", "03 my business 2020"] For $sTxt in $aTxt $arr = StringRegExp ($sTxt, "\D?(\d{2}|\d{4})(?=\D|$)", 3) _ArrayDisplay ($arr) Next Terenz 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Terenz Posted March 14, 2020 Author Share Posted March 14, 2020 Cool! Thanks! Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now