1

I have an SVN log being captured in PowerShell which I am then trying to modify and string off everything except the file URL. The problem I am having is getting a regex to remove everything before the file URL. My entry is matched as:

M /trunk/project/application/myFile.cs

There are two spaces at the beginning which originally I was trying to replace with a Regex but that did not seem to work, so I use a trim and end up with:

M /trunk/project/application/myFile.cs

Now I want to get rid of the File status indicator so I have a regular expression like:

$entry = $entry.Replace("^[ADMR]\s+","")

Where $entry is the matched file URL but this doesn't seem to do anything, even removing the caret to just look for the value and space did not do anything. I know that $entry is a string, I originally thought Replace was not working as $entry was not a string, but running Get-Member during the script shows I have a string type. Is there something special about the svn file indicator or is the regex somehow off?

0

2 Answers 2

2

Given your example string:

$entry = 'M /trunk/project/application/myFile.cs'
$fileURL = ($entry -split ' /')[1]
Sign up to request clarification or add additional context in comments.

1 Comment

I was so focused on trying to get this done in a regex I completely forgot about split. Would be nice to get the whole thing in a regex but life sometimes gives you lemons
1

Your regex doesn't work because string.Replace just does a literal string replacement and doesn't know about regexes. You'd probably want [Regex]::Replace or just the -replace operator.

But when using SVN with PowerShell, I'd always go with the XML format. SVN allows a --xml option to all commands which then will output XML (albeit invalid if it dies in between).

E.g.:

$x = [xml](svn log -l 3 --verbose --xml)
$x.log.logentry|%{$_.paths}|%{$_.path}|%{$_.'#text'}

will give you all paths.

But if you need a regex:

$entry -replace '^.*?\s+'

which will remove everything up to (and including) the first sequence of spaces which has the added benefit that you don't need to remember what characters may appear there, too.

2 Comments

I do this for something else but was trying to avoid it this time since it was not meeting my needs later on. I might revisit though.
Well, expanded the answer now after actually reading the question ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.