in reply to Re^2: extra spaces between the characters in string
in thread extra spaces between the characters in string

That's funny. In your original post you said "the first word", and demonstrated input with leading numeric digits that you removed from the output. But I wouldn't call changing "first word" to "first three words" a matter of being clear. I would call that changing the specification.

If by "word" you mean clumps of characters separated by white space, you could change the original regexp to:

s/^(?:\S+\s+){3}//

In other words, take the first three occurrences of clumps of characters which could be anything that is not space, followed by one or more spaces. Repeat that three times. And then substitute those three occurrences with an empty string.

As before, test your output on the screen before committing to a file.


Dave

Replies are listed 'Best First'.
Re^4: extra spaces between the characters in string
by harshashende (Initiate) on Jun 09, 2011 at 07:20 UTC

    Once again Thanks Dave, regex really reduces the code to great extend. Also , got the solution to extra spaces between character. It was problem of UTF-16 character encoding.

    Thanks every one :). But I want to learn how write complex regex code. Can you tell me some good links for that .

      Start with perlretut, then perlre, as well as perlop (the section on regexp quote like operators).

      But if you have $30 to spend, and a desire to really learn regular expressions, visit the O'Reilly site and order Mastering Regular Expressions (as of this moment, 3rd edition is current). There's no substitute for the best.


      Dave