ReconX Posted December 23, 2020 Share Posted December 23, 2020 (edited) So, every time I try to understand the formulas for StringRegExp, my brain goes to mush. Someone on the forum helped me with a previous question I had, and wrote this piece of code for me. I set out to understand it, and hopefully have. I've written what I think the code means. It was to help separate "Movie (2002)" to two separate strings being "Movie" and "2002". The code in full is, "([^\\]*?)\h*\((\d+)\)". ([^\\]*?) ( = Opens capture group. [ = Opens Expression. ^ = Matches any character not in the set. Meaning anything besides "\". \ = Determines Metacharacter. \ = Looks for character "\" determined by the previous "\". ] = Closes Expression *? = More Lazy ) = Closes capture group. \h* \h = Matches horizontal whitespace characters. * = More greedy. \((\d+)\) \ = Determines Metacharacter. ( = Looks for character "(" determined by the previous "\". ( = Opens capture group. \d = Looks for digits 0-9. + = More greedy ) = Closes capture group \ = Determines Metacharacter. ) = Looks for character ")" determined by the previous "\". Am I on the correct path? Edited December 23, 2020 by ReconX Link to comment Share on other sites More sharing options...
iamtheky Posted December 23, 2020 Share Posted December 23, 2020 it seems to do the thing. However, if you just want two groups "date / everything else" and if all of your titles have a parenthetical 4 digit year at the end of the string, then i would be specific about the number of digits and end of the string. Scoops up a bunch of edge cases with a small modification. $s = "Movie (0000) (part1000) (2002)" ;~ $a = stringregexp($s , "([^\\]*?)\h*\((\d+)\)" , 3) ;~ _ArrayDisplay($a) $a = stringregexp($s , "(.*?)(\(\d{4}\)\z)" , 3) _ArrayDisplay($a) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mikell Posted December 23, 2020 Share Posted December 23, 2020 7 minutes ago, iamtheky said: Scoops up a bunch of edge cases with a small modification To just add a little '$' to the previous expression was not good enough ? #Include <Array.au3> $s = "Movie (0000) (part1000) (2002)" $a = stringregexp($s , "([^\\]*?)\h*\((\d+)\)$" , 3) _ArrayDisplay($a) @ReconX The best way is to translate the expression in common language , i.e. ([^\\]*?) means : "please capture 0 or more non-backslash characters (lazy way)" , or \((\d+)\) means : "please capture one or more digits enclosed with parenthesis" iamtheky 1 Link to comment Share on other sites More sharing options...
iamtheky Posted December 23, 2020 Share Posted December 23, 2020 you know i dont know what any of those characters mean. if i cant .*? it, i use yours. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Bert Posted December 24, 2020 Share Posted December 24, 2020 (edited) You know - in the help file there is the "Tutorial - Regular Expression" and at the bottom is a button with a that will open a script in SciTE. Run that script and you will find it to be a GUI for testing various StringRegExp() patterns. Looks like this: Edited December 24, 2020 by Bert abberration 1 The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
mikell Posted December 24, 2020 Share Posted December 24, 2020 15 hours ago, iamtheky said: you know i dont know what any of those characters mean Hmm I also know that this assertion is not exactly true But I'm surprised you didn't suggest such a solution $s = "Movie (0000) (part1000) (2002)" $r = StringSplit(StringMid($s, 1, StringInStr($s, "(", 0, -1)-1) & @crlf & StringMid($s, StringInStr($s, "(", 0, -1)+1, 4), @crlf, 3) _ArrayDisplay($r) iamtheky 1 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