1
$\begingroup$

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"}.

$\endgroup$
2
$\begingroup$
texttest = "walking walk routes walks"
StringSplit[texttest, " "] /. {"walk" -> "walking", "walks" -> "walking"}

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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