Avatar of Skale
Skale
 asked on

How to find a specific pattern in a string and replace it in C#

I have a term like sub_id() and i would like to change it to "x" from string like below;

$_PR_frsub_id()_tyu --> $_PR_frx_tyu

but problem it sometimes takes some value inside it like sub_id(12546) so it's not easy to replace it with sub_id() we have to define where first bracket starts and ends sub_id(n character)

$_PR_frsub_id(123456)_tyu --> $_PR_frx_tyu


Any help would be grateful.
C#

Avatar of undefined
Last Comment
Juan Carlos

8/22/2022 - Mon
SOLUTION
Marcus Keustermans

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Skale

ASKER
Thanks for the solution it really fits but i forgot two "+" at the beginning and ending.

$_PR_fr+sub_id()+_tyu --> $_PR_frx_tyu
Skale

ASKER
it doesnt work with that :/ -> "+sub_id\((.*?)\)+", "x"

It gives error this type of writing.

EDIT:
\"+sub_id\((.*?)\)+\", "x" it worked. Thank you.
ASKER CERTIFIED SOLUTION
Juan Carlos

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck