test <- c("i really wasn aware and i wasnt aware at all. but i wasn't aware. just wasn't. this wasn45'e meant to be. it wasn@'re simple", "Wasn&^$tt that nice?", "You say wasnmmmt?", "No, he wasn&#t#@$.", "She wasn%#@t##, I know.")gsub("\\b(wasn)\\S*\\b(?:\\S*(\\p{P}))?", "\\1't\\2", test, ignore.case=TRUE, perl=TRUE)
Standard input is empty
[1] "i really wasn't aware and i wasn't aware at all. but i wasn't aware. just wasn't. this wasn't meant to be. it wasn't simple" [2] "Wasn't that nice?" [3] "You say wasn't?" [4] "No, he wasn't." [5] "She wasn't, I know."
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!