CodeIgniter Forums
Regular Expression - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Regular Expression (/showthread.php?tid=52315)



Regular Expression - El Forum - 06-06-2012

[eluser]Tominator[/eluser]
Hello I have a problem with regexp. I want to negate whole word.

I want my string to starts with foo, ends with bar and do not contain any other foo inside.
I was trying to achieve that using [^foo], and it works, but the problem it returns 0 in 'fo' and 'f' also. I have found (?!foo) and (?<!foo), and I'm trying for hours now, but I can't make it.

Correct (regexp should return 1):
foo something bar
foofo bar
foo fo bar
foo fobar

Incorect (regexp should return 0):
foo foo bar
foofoo bar
foo foobar
foo somethingfoosomething bar

In sentence it would be: String is OK, when there is no foo between foo and bar.

I'm looking forward to an answer Big Grin

Edit: I have forgotten to say, that this pattern can be anywhere in biggest string like: Say foo foo bar my honey.

Edit2: Maybe I'm doing it all wrong. I want to create recursive condition. Like that:
Quote:[(keyword)] parent text [(keyword)] child text [(ending_keyword)] [(ending_keyword)]

Tom