SirAlonne Posted February 18, 2020 Share Posted February 18, 2020 (edited) Hi! I've been experimenting for a while with this but it seems I stuck in a wall or missing something.. So let's say i have a string and I want an unknown length sequence number (in this case the 11) so I used: Local $String = "john.wick.cv. 2019.russian 666_roulette 11.pdf" StringRegExpReplace($String, "^.*\h|D", "", Default) ; This retrieved "11" BUT if the filename changes "john.wick.cv.2019.russian 666_roulette11.pdf" because a retarted user accidentally forgot to put space before the number, then the previous method does not works.. Is there a way to retrieve the sequence with regular expressions starting from right hand side? To summarize it more briefly: The filename could be anything The sequence number always at the end of the filename followed by the dot and the extension The sequence number could be any length (\d+) The filetype is a set of extensions (.pdf .psd .ai .blend) Edited February 18, 2020 by SirAlonne Link to comment Share on other sites More sharing options...
mikell Posted February 18, 2020 Share Posted February 18, 2020 Try this StringRegExpReplace($String, ".*\D(\d+).*", "$1") SirAlonne 1 Link to comment Share on other sites More sharing options...
Nine Posted February 18, 2020 Share Posted February 18, 2020 Nice mikell, but I would change to ".*\D(\d+)\..*" in case there is a number in the extension (ex.au3) SirAlonne 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...
SirAlonne Posted February 18, 2020 Author Share Posted February 18, 2020 Thanks @mikell and @Nine ! I just solved it right after sending the post but it seems mine is a bit too complicated.. $String = StringRegExpReplace($String, "(?i).*?((\d+)(\.)(\b(pdf)\b|\b(psd)\b|\b(ai)\b|\b(blend)\b)).*?$", "$1") $String = StringRegExpReplace($String, "\D", "") Link to comment Share on other sites More sharing options...
iamtheky Posted February 18, 2020 Share Posted February 18, 2020 oh, we can complicate things Local $String = "john.wick.cv. 2019.russian 666_roulette5711.pdf" msgbox(0, '' , stringreverse(number(stringreverse(stringmid($String , 1 , stringinstr($String , "." , 0 , -1) - 1))))) seadoggie01 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
jguinch Posted February 18, 2020 Share Posted February 18, 2020 StringRegExpReplace($String, ".*?(\d+)\.(?:pdf|psd|blend)$", "$1") SirAlonne 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
mikell Posted February 18, 2020 Share Posted February 18, 2020 6 hours ago, Nine said: in case there is a number in the extension Absolutely right... but as usual I strictly followed the requirements mentioned in post #1 8 hours ago, SirAlonne said: The filetype is a set of extensions (.pdf .psd .ai .blend) 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