abberration Posted February 29, 2020 Share Posted February 29, 2020 Hi, all I'm trying to figure out how to regex a string like Software.Log.W01D01.Extended.Info.txt to only show text up to the W01D01 and to substitute the periods with spaces. So far, I have been able to capture the text up to the W01D01. On a regex play website, I found to not select a character, use ^\.+ or at least it seems to work when I'm playing with the code. Here is a test code: #include "Array.au3" $varTempInfo = "Software.Log.W01D01.Extended.Info.txt" $varNameFormattedForSearch = StringRegExp($varTempInfo, ".+?(?=[W]\d\d[D]\d\d)", 1) _ArrayDisplay($varNameFormattedForSearch) The best attempt I have made so far is this: (^\.+)?.+?(?=[W]\d\d[D]\d\d)|^\.+ Other failed attempts are: .+?(?=[W]\d\d[D]\d\d)|($&[.]) .+?(?=[W]\d\d[D]\d\d)?($&[.]) ($&[.])|(.+?(?=[W]\d\d[D]\d\d)) .+?(($&[.])?=[W]\d\d[D]\d\d) Does anyone know how to do it right? Thanks! Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
seadoggie01 Posted February 29, 2020 Share Posted February 29, 2020 Could you explain the expected result please? It sounds like you want just the portion that says "W01D01", but you also mention turning periods into spaces. To capture the W##D## portion, you can use this: (W\d{2}D\d{2}) Also realize that once you head too far down the road of Regular Expressions, you'll eventually realize that it should be split into multiple steps. Beware that time. All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Malkey Posted February 29, 2020 Share Posted February 29, 2020 (edited) 2 hours ago, abberration said: .... On a regex play website, I found to not select a character, use ^\.+ or at least it seems to work when I'm playing with the code. .... The PCRE (Perl Compatible Regular Expressions) engine flavour used with AutoIt, "^\.+" will match one or all ("+") of the consecutive literal dots ("\.") at the beginning of the test string ("^"). Local $varTempInfo = "Software.Log.W01D01.Extended.Info.txt" Local $varNameFormattedForSearch = StringRegExpReplace($varTempInfo, "(\.W[\w]{5}+.+$)|\.", " ") ConsoleWrite($varNameFormattedForSearch & @CRLF) ; Returns:- Software Log Edited February 29, 2020 by Malkey Link to comment Share on other sites More sharing options...
abberration Posted March 1, 2020 Author Share Posted March 1, 2020 2 hours ago, seadoggie01 said: Could you explain the expected result please? It sounds like you want just the portion that says "W01D01", but you also mention turning periods into spaces. To capture the W##D## portion, you can use this: (W\d{2}D\d{2}) Also realize that once you head too far down the road of Regular Expressions, you'll eventually realize that it should be split into multiple steps. Beware that time. On the example I gave, I want to see the following text from regex (not including the quotes): "Software Log " I like your more condensed version using {2} because in the future I may run into instances where I have 4 or more numbers. And splitting it into multiple steps is what I did for a quick fix. I just thought it might be possible to do two things (get all the text to the left of W01D01 and eliminate all periods from that selected text) at the same time - a learning experience, maybe. Thanks for the improved code. I will make note of it. 1 hour ago, Malkey said: The PCRE (Perl Compatible Regular Expressions) engine flavour used with AutoIt, "^\.+" will match one or all ("+") of the consecutive literal dots ("\.") at the beginning of the test string ("^"). Local $varTempInfo = "Software.Log.W01D01.Extended.Info.txt" Local $varNameFormattedForSearch = StringRegExpReplace($varTempInfo, "(\.W[\w]{5}+.+$)|\.", " ") ConsoleWrite($varNameFormattedForSearch & @CRLF) ; Returns:- Software Log I'm impressed, your code works, but I am not well versed in regex yet, so I don't know how it works. I will be researching every part of your code tomorrow night. Thank you for working on this. I really appreciate it! Easy MP3 | Software Installer | Password Manager 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