Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excluding phrases from regular expression

Status
Not open for further replies.

wapoc

Programmer
Jan 29, 2003
14
FR
This should be simple, but I can't figure it out.

Let's say I want to check if my input does not contain the word 'hello'.

In my mind this is the equivalent of [^(hello)]+ but that obviously doesn't work.

This is for a strict parser of tags and therefore I have to exclude whole words. Am I able to do this with regular expressions, or do I have to do it manually?

Cheers,
Rob
 
Why not use a simple strpos() to do this..

Code:
$str = "hello" ;
$fullstr = "hello world!" ;
$pos = strpos( $fullstr, $str ) ;

if ( $pos === false  ) {
	echo "string does not contain $str word" ;
}
else {
	echo "string contains $str word" ;
}

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
I need it for replacement too. It's a tag parser, and it's strict, e.g.:

text is ok
text is ok
t][t is ok
text is not
text is not

etc.
 
Whoops! That'll teach me to preview.

text is ok
text is ok
t[xt is ok
text is ok

but

text is not
text is not
text is not

and so on.
 
hi,
you can try with preg_match().

Code:
if (preg_match("/your_regex/", $input_str, $matches_array)==0)
{
   // doesnt match the reg_exp

}else
{
   // the reg_exp was found
};




___
____
 
>>text is not

what should be done when such a syntax is encountered? should the file just display the text as is or try to change it to HTML???

Known is handfull, Unknown is worldfull
 
It should convert it to WML (strict HTML for mobiles), so bad syntax is not permissible.

Apologies for not being clearer!

I think my best bet may be to use the standard PHP string functions and parse it myself, but I'd still like to know if it's possible to exclude a phrase from a regular expression.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top