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 : Malei want to replace all
Ageto30by 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 : MaleThe following regex S/R :
SEARCH
(?<=Age : )\d+(?=.*\R\h*Sex : Male)REPLACE
30Would 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 : MaleBest 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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login