re = /(?<=(\/\/\[JsonProperty\(Required = Required\.Always\)]\n)|(\/\/\[JsonProperty\(DefaultValueHandling = DefaultValueHandling\.Ignore\)]\n))( public [a-zA-Z]+ )/m
str = 'namespace Telegram.Bot.Types.Payments
{
/// <summary>
/// This object contains information about an incoming pre-checkout query
/// </summary>
//[JsonObject(MemberSerialization.OptIn, NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
public sealed record PreCheckoutQuery
{
/// <summary>
/// Unique query identifier
/// </summary>
//[JsonProperty(Required = Required.Always)]
public string Id { get; set; }
/// <summary>
/// User who sent the query
/// </summary>
//[JsonProperty(Required = Required.Always)]
public User From { get; set; }
/// <summary>
/// Three-letter ISO 4217 currency code
/// </summary>
//[JsonProperty(Required = Required.Always)]
public string Currency { get; set; }
/// <summary>
/// Total price in the smallest units of the currency.
/// </summary>
//[JsonProperty(Required = Required.Always)]
public int TotalAmount { get; set; }
/// <summary>
/// Bot specified invoice payload
/// </summary>
//[JsonProperty(Required = Required.Always)]
public string InvoicePayload { get; set; }
/// <summary>
/// Optional. Identifier of the shipping option chosen by the user
/// </summary>
//[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string ShippingOptionId { get; set; }
/// <summary>
/// Optional. Order info provided by the user
/// </summary>
//[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public OrderInfo OrderInfo { get; set; }
}
}
'
subst = ' [JsonPropertyName("")]\\n$0'
result = str.gsub(re, subst)
# Print the result of the substitution
puts result
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html