-1

I want to check for a specific word not in a given paragraph.

The following excluded words should not be in my paragraph.

<script>
<src>
<img>

I tried this regular expression and it worked only for one single line paragraph. It does not work for multiline paraghraphs.

"^(((?!^.*k(script|src|img)k)).*)*$";
Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
shan
  • 1
  • 2
    Define "paragraph". Also, what are the `k`s surrounding your keywords supposed to do? – Tim Pietzcker Nov 20 '11 at 08:37
  • Which programming language is this? – Mateen Ulhaq Nov 20 '11 at 08:38
  • @muntoo: PHP, obviously, from the `preg-match` tag. – Tim Pietzcker Nov 20 '11 at 08:40
  • 1
    @TimPietzcker Not obvious to non-PHP'ers. [tag:preg-match] does not have a tag summary. – Mateen Ulhaq Nov 20 '11 at 08:44
  • See also: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – Mateen Ulhaq Nov 20 '11 at 08:47
  • Are you trying to ensure that the text in question does not contain unwanted HTML? That is somewhat different to merely searching for excluded 'words'. – Duncan Babbage Nov 20 '11 at 10:00
  • shan, welcome to stackoverflow. Your question is a bit hard to answer because some information is missing. Do you want to filter HTML input? Do you want to remove these tags? Or do you just want to test if one of those tags exists or not? And can you add some of your code what you tried so far, so it's more clear what a paragraph is and what this is about? – hakre Nov 20 '11 at 10:05

1 Answers1

0

I don't get what you are saying exactly, but:

If you want to verify a 'paragraph' does not contain the given 'words', just use this:

if(!Regex(paragraph, "^.*?<(script|src|img).*?>.*$")
{
    // Does not contain.
}
Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135