in reply to Re: Beginner question about search and replace
in thread Beginner question about search and replace

Why the (?: ) around the space character? It runs just fine as below.

s/(\d)\s+/$1;/g;

Replies are listed 'Best First'.
Re^3: Beginner question about search and replace
by luis.roca (Deacon) on Sep 16, 2011 at 15:45 UTC

    "Why the (?: ) around the space character? It runs just fine as below?"

    It does work well and is less complex to explain. I use the (?: ) to show the practice of not capturing matches into memory which wont be used in the replacement. In this specific example memory isn't going to be a problem because we're only dealing with a single string. But I personally like using it even as a way to mark what I want and don't want to work with in the replacement.

    "...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." — Don Quixote

      Fair enough. I was just curious if I was missing something. Thanks

Re^3: Beginner question about search and replace
by AnomalousMonk (Archbishop) on Sep 16, 2011 at 18:30 UTC

    I agree with luis.roca's use of  (?:\s)+ in a pedagogic or self-documentary context as already explained above.

    I would be inclined to quibble with the use of  (?:\s)+ versus  (?:\s+) especially in a pedogogic example. While these two expressions behave in exactly the same way in all respects AFAIU, the corresponding capturing expressions  (\s)+ and  (\s+) behave very differently as to the characters captured, and in an explanatory example this might, by suggestion or implication, lead to great confusion.