const regex = /(?<=(\/\/\[JsonProperty\(Required = Required\.Always\)]\n)|(\/\/\[JsonProperty\(DefaultValueHandling = DefaultValueHandling\.Ignore\)]\n))( public [a-zA-Z]+ )/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<=(\\\/\\\/\\[JsonProperty\\(Required = Required\\.Always\\)]\\n)|(\\\/\\\/\\[JsonProperty\\(DefaultValueHandling = DefaultValueHandling\\.Ignore\\)]\\n))( public [a-zA-Z]+ )', 'gm')
const 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; }
}
}
`;
const subst = ` [JsonPropertyName("")]\n$0`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', 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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions