Score:1

replace with regular expression in azure devops

cn flag

I want to take this buildVariable

Build.SourceVersion

which will equal for example:

0gc58d92d905d62415b8866g3f48f17416da426s

And replace from digit [7] till line end with empty string

0gc58d92

I tried

- ShortCommitId: ${{ replace(variables['Build.SourceVersion'], '[[8]-$]','') }}

but it didn't work

Score:1
ch flag

The substring() method will take the string value from Build.SourceVersion and can be passed two int parameters. One will output the string value starting at a specific character position, and the other tell it what subsequent character positions characters to output.

$a = "0gc58d92d905d62415b8866g3f48f17416da426s"
$a.substring(0,7)

Output

0gc58d9

Pass the substring() method just one int parameter telling it the starting character position to just output all subsequent character position characters until the end of the string.

$a = "0gc58d92d905d62415b8866g3f48f17416da426s"
$a.substring(8)

Output

d905d62415b8866g3f48f17416da426s

Supporting Resource

  • Substring()

  • String.Substring Method

    Substring(Int32)

    • Retrieves a substring from this instance. The substring starts at a specified character position and continues to the end of the string.

    Substring(Int32, Int32)

    • Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length.
Pimp Juice IT avatar
ch flag
This solution should help you get what you need, but let me know if you run into any snag, I'm happy to adjust to accommodate further if needed.
Omar Aladdin avatar
cn flag
I'm sorry but it didn't
Pimp Juice IT avatar
ch flag
@Shnbook If you have this value to start with `0gc58d92d905d62415b8866g3f48f17416da426s` what is the desired (or an example) final result you want that to be. I probably just need to understand better but if you can help clarify a little further to help me better understand, I should be able to help you figure out what you need. Let me know.
Pimp Juice IT avatar
ch flag
@Shnbook See above comment but if you can share more of the fully logic in a script, etc. you are using, that may help me fine tune this method better for your use case. Otherwise, I'm left to play with a string basically but if that's not working for your command when you integrate it, I just need to see more logic to see what trivial adjustments are needed to make it work properly.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.