• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regular Expression

#1
[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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.