I imported a text and seperated al words by using StringCases. After this I would like to manipulate the text, for example to replace all singular verbs to plural. When I use StringReplace, then Mathematica search for a part of the string and replaced it.

For example

texttest = "walking walk routes walks"
texttest1 = StringCases[texttest, RegularExpression["\\w(?<!\\d)[\\w'-]*"]];
newwords= {"walk" -> "walking", "walks" -> "walking"};
texttest2 = StringReplace[texttest1, newwords];

The result is:

{"walkinging", "walking", "routes", "walkings"}

I would like to get: {"walking", "walking", "routes", "walking"}.


1 Answer 1

texttest = "walking walk routes walks"
StringSplit[texttest, " "] /. {"walk" -> "walking", "walks" -> "walking"}

{"walking", "walking", "routes", "walking"}


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.