I’m trying to rereplace any words that begin with @ in my string…
I’ve tried a number of variations, but none of them seem to be working…
rereplace(getMessages.term, "[\s]?\B@\w+", "", "ALL")
Any suggestions?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
CF’s built-in regex doesn’t support look-behinds, which is what you need to achieve this (since you want to look “behind” (before) the @ and verify what is/isn’t there, without including it in your match).
However you can easily dip into Java, to make use of Java’s regex support (which does support look-behinds), as simply as this:
The
(?<!\w)part is a negative look-behind saying “make sure there is no \w before this position”.You might also want to consider using
(?<!\S)which will prevent any non-whitespace character, or if you need to match specific characters then use(?<![a-z_\-.,])or whatever.