From: Chai Muang thong Date: 2008-11-27T01:42:26+09:00 Subject: regexp problem Hi, I have been searching on the Internet about how to solve my problem. I have a string that needs to be split using regexp in ruby. The problem is that I cannot find a way to get it right. The string has a fix format. The rules for matching are as followed: 1)A string starts and end with any character string 2)Matching string starts from "<<" and end with ">>" 3)Matching string must be a pair of "<<" and ">>" and must be nested correctly 4)There may be any unwanted string between matching pairs but never be inside the pairs A sample string is as followed: str = "<> <>>>>> <> or <>>>>>" The result string I am looking for from the above string should be as followed: ["<> <>>>>>", "<>", "<>>>>>"] The closest I could come up with is str.split(/(<<[^>].*(>>)+)/) and I got the result as followed: ["", "<> <>>>>> <> <>>>>>", ">>"] I cannot change the rule (using "<<" and ">>), so I had little experience on how to match 2 consecutive characters. It would be appreciated if anyone has an input or suggestion. Thank you. Chai -- Posted via http://www.ruby-forum.com/.