I have some legacy code which uses "[[:punct:]]+" in a regular expression replace (using PHP's ereg_replace) to remove all punctuation chars. Eg: ereg_replace('[[:punct:]]+', 'test1-2,3.4:5', '') returns 'test12345' What I want to do is remove all punctuation except "-", ie to get the result "test1-2345". I can't currently think of a regex that will do it, other than [^\.,:]+ where I list all punctuation except - between the square brackets, but that would be a nightmare to create and maintain. Is there a way to invert [:punct:] somehow so that [^-[:inverted-punct:]]+ would work? -- Mark Rogers // More Solutions Ltd (Peterborough Office) // 0845 45 89 555 Registered in England (0456 0902) at 13 Clarke Rd, Milton Keynes, MK1 1LG
Mark Rogers wrote:
Is there a way to invert [:punct:] somehow so that [^-[:inverted-punct:]]+ would work
Solved it within seconds of hitting send... [^-[:^punct:]]+ .. does what I want, but it seems not to be supported by ereg_replace; it was trivial to change to preg_replace however. -- Mark Rogers // More Solutions Ltd (Peterborough Office) // 0845 45 89 555 Registered in England (0456 0902) at 13 Clarke Rd, Milton Keynes, MK1 1LG
participants (1)
-
Mark Rogers