http://qs1969.pair.com?node_id=708984

scarus has asked for the wisdom of the Perl Monks concerning the following question:

How can the string "USERs/User_01/user_01.config" can be extracted from the follwoing?
<include>$CONFIGURATION_PATH$/USERs/user_01/user_01.config</include>

Replies are listed 'Best First'.
Re: Extract a string
by ikegami (Patriarch) on Sep 04, 2008 at 10:31 UTC

    I presume what you want is to determine what's between the include tags, ignoring the leading '$CONFIGURATION_PATH$/'.

    my ($desired) = $original =~ m{^<include>\$CONFIGURATION_PATH\$/(.*)</include>$};

    Update: Removed stray slash in regexp.

Re: Extract a string
by Grey Fox (Chaplain) on Sep 04, 2008 at 14:13 UTC
Re: Extract a string
by eff_i_g (Curate) on Sep 04, 2008 at 16:11 UTC
    Is this truly in XML?
    Will there be multiple include pairs (elements)?
Re: Extract a string
by johndageek (Hermit) on Sep 05, 2008 at 19:07 UTC
    Jst for fun and since I know compuers can be a wee bit picky, your string "USERs/User_01/user_01.config" will never be fouind in the string "<include>$CONFIGURATION_PATH$/USERs/user_01/user_01.config</include>"

    User_01 and user_01 do not match due to case difference.

    use uc() on both sides of the strnig and attempt a compare.

    Enjoy!
    Dageek