
pnajafi
New User
Jan 7, 2011, 10:04 AM
Post #1 of 4
(8136 views)
|
regex removing similar enteries
|
Can't Post
|
|
Hi There, I have the following text (it is not a regex rather a file path followed by space followed by more text): /next/ whatevertext /next whatevertext /Next watevertext /next/next wordswords /next/ words Result of the match should be as follows: The first 3 lines: the result of this match should be only one line: /next whatevertext (given that "whatevertext" is also the same in all the 3 lines) this is because "\next", "\Next" and "\next\" are all similar and I want only the one lowercase with no slash at the end. The last two lines are selected as well, because "/next/next" and "/next/" are different. My attempted regex Pattern is: So what I did in the pattern is to say zero or more characters (.*), alternatively ending with a slash (\/)? then space then zero or more characters (.*). Now ((.*)(\/)? (.*)){1} means that all in the bracket happens at most once. And case insensitive is set using i flag ; however upon testing I am not getting the result I am looking for. I think the problem lies in the fact that I am looking for something that happens at most once but it happens 3 times, so I would only (probably get only the last 2 distinct lines). So how do I go about it? Any help is appreciated.
|