Reputation: 78
I am trying to search in a string for a certain value and replace it with another value.
The example:
String: "/accounts/{accountId}/cheques/{chequeId}/cancel"
I am trying to replace anything between { and } with the number 1.
So I would end up with:
String: "/accounts/1/cheques/1/cancel"
I am using the following:
prepedURI = System.Text.RegularExpressions.Regex.Replace(prepedURI, "{.*}", "1")
But unfortunately, the Replace function is returning: String: "/accounts/1/cancel"
It seems to be ignoring the first } and replacing everything up to the 2nd }.
Any advice?
Excuse my dumb. This is my first Regex experience, and I am trying my best to understand all these 'flags' in the pattern.
Example (you can paste into a button click event to see what I mean):
Dim prepedURI As String = "/accounts/{accountId}/cheques/{chequeId}/cancel"
prepedURI = System.Text.RegularExpressions.Regex.Replace(prepedURI, "{.*}", "1")
MsgBox(prepedURI)
Upvotes: 2
Views: 255
Reputation: 9621
Use ? before the closing curly brace
{.*?}
Working example can be found at the following link - http://rubular.com/r/1LpnGNC3sC
Upvotes: 1