Sunday, October 6, 2013

How to match an apostrophe (') unless it is escaped (\')?

Is it possible to construct a regular expression for this? If so, I’d appreciate if someone shows how.

Use this regular expression:

(?<!\\)'

It means match all apostrophe chars not preceeded by a backslash (the backslash is escaped itself because it is a special char for regexps)

No comments:

Post a Comment