# Regular Expressions: How to Substitute

**URL:** https://www.finalbuilder.com/forums/t/regular-expressions-how-to-substitute/2220
**Category:** Discussion
**Created:** [November 14, 2013, 4:44am UTC](https://www.finalbuilder.com/forums/t/regular-expressions-how-to-substitute/2220 "2013-11-14T04:44:46Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![michael.jelich](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/m/c57346/32.png) [@michael.jelich](https://www.finalbuilder.com/forums/u/michael.jelich)
#### Post date: [November 14, 2013, 4:44am UTC](https://www.finalbuilder.com/forums/t/regular-expressions-how-to-substitute/2220/1 "2013-11-14T04:44:46Z")

</div>

Hi Support Team,

I use the Perforce actions and want to determine a workspace root folder. For that I use Perforce Generic command with the 'client' command. Arguments are "-o %P4WorkSpace%". This brings the following output, which I log to a variable (shortened):

Owner:&nbsp; Michael  
Root:&nbsp;&nbsp; F:\Daten\Perforce  
SubmitOptions:&nbsp; revertunchanged

In order to get a clue of how to grab the root folder name I use "TRegExpr 0.947 test program". The following regular expression works well:

(?mg-si)Root:\s\*(.\*)$

When I use $1 als template string on the 'substitute' tab card, the substitution result is F:\Daten\Perforce.

Unfortunately it seems that there is no FB Action available providing any similar.

I only see the Text Replace Action dealing with regular expressions - but here I only can use substitution in replacements. Using $1 as replacement string will lead to the following text:

Owner:&nbsp; Michael  
F:\Daten\Perforce  
SubmitOptions:&nbsp; revertunchanged

Do you know any other action providing substitution without replacement or would you mind to give me a hint of how to extract the desired portion of text without a list iterator or further regular expression replacements (removing the part before and after...)?

Best regards  
Michael

---

<div class="post-metadata">

### Author: ![michael.jelich](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/m/c57346/32.png) [@michael.jelich](https://www.finalbuilder.com/forums/u/michael.jelich)
#### Post date: [November 14, 2013, 5:47am UTC](https://www.finalbuilder.com/forums/t/regular-expressions-how-to-substitute/2220/2 "2013-11-14T05:47:39Z")

</div>

Hi Support Team,

forgot my post - I worked out a regular expression removing the leading and trailing part and using this I can use the existing action.

For other users having similar problems here is the regular expression:

(?ims)\A.\*^Root:\s\*(?-s)(\S.\*$)(?s).\*\Z

In $1 is the folder name.

Best regards  
Michael
