SirAlonne Posted February 18, 2020 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
mikell Posted February 18, 2020 Posted February 18, 2020 Try this StringRegExpReplace($String, ".*\D(\d+).*", "$1") SirAlonne 1
Nine Posted February 18, 2020 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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
SirAlonne Posted February 18, 2020 Author 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", "")
iamtheky Posted February 18, 2020 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 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
jguinch Posted February 18, 2020 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
mikell Posted February 18, 2020 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)
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