Need Help to replace a text by finding other text as keyword
-
i want to find specific word but using other text as keyword. is it possible?
For Ex:
-Name : David Age : 20 Sex : Male -Name : Sara Age : 23 Sex : Female -Name : Felicia Age : 21 Sex : Female -Name : Erick Age : 25 Sex : Male
i want to replace all
Age
to30
by finding keywordmale
.
thanks -
@Hendrick-Thea
Find:(?-s)(Age\h+:\h+)(\d{1,2})(.*\RSex\h+:\h+Male)
Replace:
${1}30${3}
Assumption: no male is older than 99 years.
-
Hello, @hendrick-thea, @paul-wormer and All,
An alternate solution, which allow leading indentation :
So, from this INPUT tet :
-Name : David Age : 20 Sex : Male -Name : Sara Age : 23 Sex : Female -Name : Felicia Age : 21 Sex : Female -Name : Erick Age : 25 Sex : Male
The following regex S/R :
SEARCH
(?<=Age : )\d+(?=.*\R\h*Sex : Male)
REPLACE
30
Would produce this OUTPUT text :
-Name : David Age : 30 Sex : Male -Name : Sara Age : 23 Sex : Female -Name : Felicia Age : 21 Sex : Female -Name : Erick Age : 30 Sex : Male
Best Regards,
guy038
-
All of the above solutions are good, but they are not necessarily very robust to reformatting of the document, which appears to be YAML.
Normally this is where I’d recommend a plugin or a PythonScript solution for working with YAML, but I don’t know of any plugins, and Python’s YAML package is not in the Python standard library, so using PythonScript for YAML isn’t a great option.
Having said that, my general suggestion for performing these kinds of manipulations on YAML documents is to learn a scripting language (I recommend Python) and using that to write normal Python scripts. If you end up going that route, this forum will cease to be a useful resource and StackOverflow becomes one of your best friends.