Вывод git show-ref --heads
является машиной.
$ git show-ref --heads
a419c3625028324901ce09533de6377740c9b551 refs/heads/branch_foo
38760602162a7e7aa7c75f1797342f3b65262999 refs/heads/some/branch_bar
Если вам просто нужны имена ветвей, что-то вроде этого будет делать следующее:
$ git show-ref --heads | cut -d/ -f3-
branch_foo
some/branch_bar
Взгляните на Regex.Replace(string, string, MatchEvaluator)
:
http://msdn.microsoft.com/en-us/library/ht1sxswy.aspx
Это должно позволить вам пройти MatchEvaluator, который проверяет индекс конкретного совпадения, поэтому в этом случае вы можете искать index == 1
Я бы не использовал Regex только для выделения строк в тексте. Прочитайте CSV-файл с помощью
Dim lines As String()
lines = File.ReadAllLines("path of the CSV file")
Затем сделайте так, как это
For i As Integer = starting_match To last_match
lines(i) = lines(i).Replace("old","new")
Next
И поместите строки вместе с
Dim result As String
result = String.Join(System.Environment.NewLine, lines)
UPDATE
Путаница исходит из того, что начальная позиция в методе Replace
обозначает начальную позицию символа, а не начальный индекс совпадения. Поэтому я предлагаю использовать этот метод расширения
<System.Runtime.CompilerServices.Extension> _
Public Shared Function ReplaceMatches(regex As Regex,
input As String, replacement As String,
countMatches As Integer, startAtMatch As Integer
) As String
Dim matches As MatchCollection = regex.Matches(input)
If startAtMatch >= matches.Count Then
Return input
End If
Dim skippedMatch As Match = matches(startAtMatch - 1)
Dim startAtCharacterPosition As Integer = skippedMatch.Index + skippedMatch.Length
Return regex.Replace(input, replacement, countMatches, startAtCharacterPosition)
End Function
Теперь вы можете заменить на:
Dim input As String = "aaa bbb ccc ddd eee fff"
Dim startAtMatch As Integer = 2 ' ccc
Dim countMatches As Integer = 3
Dim regex = New Regex("\w+")
Dim result As String = regex.ReplaceMatches(input, "XX", countMatches, startAtMatch)
Console.WriteLine(result) ' --> "aaa bbb XX XX XX fff"
(Примеры, преобразованные из C # в VB с помощью devloperFusion )
Следующий код может помочь вам
http://msdn.microsoft.com/en-us/library/ms149475.aspx?cs-save-lang=1&cs-lang= vb # code-snippet-3
Imports System.Collections
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim words As String = "letter alphabetical missing lack release " + _
"penchant slack acryllic laundry cease"
Dim pattern As String = "\w+ # Matches all the characters in a word."
Dim evaluator As MatchEvaluator = AddressOf WordScrambler
Console.WriteLine("Original words:")
Console.WriteLine(words)
Console.WriteLine("Scrambled words:")
Console.WriteLine(Regex.Replace(words, pattern, evaluator,
RegexOptions.IgnorePatternWhitespace))
End Sub
Public Function WordScrambler(ByVal match As Match) As String
Dim arraySize As Integer = match.Value.Length - 1
' Define two arrays equal to the number of letters in the match.
Dim keys(arraySize) As Double
Dim letters(arraySize) As Char
' Instantiate random number generator'
Dim rnd As New Random()
For ctr As Integer = 0 To match.Value.Length - 1
' Populate the array of keys with random numbers.
keys(ctr) = rnd.NextDouble()
' Assign letter to array of letters.
letters(ctr) = match.Value.Chars(ctr)
Next
Array.Sort(keys, letters, 0, arraySize, Comparer.Default)
Return New String(letters)
End Function
End Module
' The example displays output similar to the following:
' Original words:
' letter alphabetical missing lack release penchant slack acryllic laundry cease
'
' Scrambled words:
' etlert liahepalbcat imsgsni alkc ereelsa epcnnaht lscak cayirllc alnyurd ecsae