Jump to content

Recommended Posts

Posted (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 by ReconX
Posted

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)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted
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 ? :idiot:

#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" :)

Posted

you know i dont know what any of those characters mean.  if i cant .*? it, i use yours. 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...