Regex search and replace with groups
Hi there, I'd like to remove a slash from a string like this one: 'abc123/456def/ghi' The resulting string should be 'abc123456def/ghi' that is only slashes surrounded by numbers should be removed. I tried with regex and group, using something like: 'abc123/456def/ghi'copyWithRegex: '(\d)/(\d)' matchesReplacedWith: '$1$2' but of course it doesn't work, dollar sign doesn't identify the group, sigh. Have you any suggestion? Cheers Davide -- View this message in context: http://forum.world.st/Regex-search-and-replace-with-groups-tp4652801.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
Any regex guru? :-) Davide -- View this message in context: http://forum.world.st/Regex-search-and-replace-with-groups-tp4652801p4652877... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
How about: 'abc123/456def/ghi'copyWithRegex: '(\d)/(\d)' matchesTranslatedUsing: [ :each | each first asString , each third asString ]. Not sure if that's the best way, but it seems to work. On Thu, Oct 25, 2012 at 1:58 AM, Davide Varvello <varvello@yahoo.com> wrote:
Any regex guru? :-) Davide
-- View this message in context: http://forum.world.st/Regex-search-and-replace-with-groups-tp4652801p4652877... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
:-) yep, Peter, it works. I was looking for something semantically related to grouping, but your solution do the stuff Thanks Davide Peter H. Meadows wrote
How about:
'abc123/456def/ghi'copyWithRegex: '(\d)/(\d)' matchesTranslatedUsing: [ :each | each first asString , each third asString ].
Not sure if that's the best way, but it seems to work.
-- View this message in context: http://forum.world.st/Regex-search-and-replace-with-groups-tp4652801p4652891... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
participants (2)
-
Davide Varvello -
Peter H. Meadows