I received a referee report on one of my articles. The report is amazing and gives me wonderful directions to improve my work however he rejected the article. Now I rewrote the article considering his comments and I am going to submit the article to a different journal. I would like to thank him or to say this version is thanks to this referee. Is this regular and how to say it?
Yes, it's certainly regular: acknowledgements to referees are not uncommon. I'd formulate the acknowledgement in the following way or similarly:
The author would like to thank the anonymous referee who provided useful and detailed comments on a previous/earlier version of the manuscript.
The qualifier earlier should be enough to disambiguate. In addition, once the paper is published, you can also write an email to the editor of the journal where you had once submitted the manuscript, asking them to pass your acknowledgement to the referee.
I wouldn't mention this at all in the acknowledgment. This is a more than usually convoluted history of a paper; most readers will be confused by it*, and nearly all readers don't care about thanks to an anonymous referee. Also, this looks to me more like throwing a letter through a window and hoping that the wind will deliver it. Just ask the editor of the previous journal to pass you thanks to the reviewer, with a link to the published paper.
*The proposition of Massimo isn't unambiguous to me: a reader may imagine there were two (or more) rounds of review for the journal that eventually published the manuscript, and two (or more) reviewers. The reviewer that's being acknowledged gave his comments only in the first round, and did not comment (did not feel it's necessary after seeing the revised version) in the next round. Personally, after seeing the sentence Massimo propose, I wouldn't even think it may about a reviewer in a previous submission to a different journal.