Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 2 down vote accepted
texttest = "walking walk routes walks"
StringSplit[texttest, " "] /. {"walk" -> "walking", "walks" -> "walking"}

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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