The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here

How to replace words based on keywords in the example

sugaroosugaroo Member Posts: 1 Learner I
I wish to replace words in an example if ever it contains a keyword. In my case, any example that contains the word "street" must be replaced by "village". So if the example contains "Elmo street" then it will be replaced into "village" thanks!

Answers

  • kaymankayman Member Posts: 662 Unicorn
    You can use regex combined with the replace operator. 
    In this specific case it can be as simple as looking for street, and replacing it by village.

    Of course, this can be tricky if you have words that contain street, so you may need to use boundaries.

    For instance, using street\b means that street only should be replaced if it's at the end of a word (so followed by a space, a dot or whatever that's not a character)

    You can do this with a single word, or with a list of words. In the latter case ordering is very important to avoid unwanted replacements. 
Sign In or Register to comment.