Question: I need to run some custom code in a User Control when a certain custom dependency property (defined in a parent User Control) has changed. What is the best way to do this in WPF?

I have spent a good bit of time playing with triggers in XAML which use data binding to access my CDP, and found a solution which requires setting an intermediate CDP (in the child user control), and then running my custom code in that second CDP's changed event. However this is pretty messy and doesn't seem to be the proper use of WPF. Also the code I am running isn't directly related to the UI, so XAML doesn't seem to be appropriate here. 

Assuming the child user control's DataContext is properly set such that I can access the CDP, how can I write code to simply execute a callback function when the CDP is changed? 

I already have an "OnXXXChanged" callback in the high-level parent control, but that control doesn't know anything about the child control so it cannot easily cause code to execute in the child control's object.

Answer: 
The problem is that matching is done in a greedy manner. `.*` will match as much as it can, which in your case means it will match more than one slash, when you really wanted it to stop at the first slash.

You should specifically match everything after `/home/user1/` but before the next `/`

```
expr /home/user1/subdir/foo_1/foo_2 : '\/home\/user1\/\([^\/]*\)'

```

which outputs:

```
subdir

```
The shell can do this by itself if you can spend a temporary variable.

```
t=${path#/home/user1/}
subdir=${t%/*}

```