1

I am trying to match if string that can be multiple lines contains any tags surrounded with < > . My regex knowledge is quite limited, so far I got to

[\s,\S]*<\/?[A-Za-z][^>]*(?!>)[\s,\S]*

What I want it to do is detect opening < , that can be followed by 1 or more characters(letters) and this cannot be followed by closing > .

I want all the text to be evaluated as match thus [\s,\S] on both sides.

So basically it should match only if no tag is detected.

With above this works: hello<p> (not match) But this not: hello <pp> (will match and should not)

Anyone who can help here?

EDIT: Let's forget about html, I would like to have regex that matches on string if it does not contain any text wrapped in <>. I can't understand how answer posted in comment answers that. I do not want to parse anything..

Example string: hello there = match Another: hello <there> = NO MATCH.

Thanks

Liam
  • 27,717
  • 28
  • 128
  • 190
JanT
  • 2,105
  • 3
  • 28
  • 35
  • 3
    Possible duplicate of [RegEx match open tags except XHTML self-contained tags](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – Liam Oct 12 '18 at 15:31
  • @Liam I am not sure I understand this.. Link you posted is about parsing, I want to match string unless it contains any text wrapped in <>. – JanT Oct 12 '18 at 15:39
  • 1
    If you just want to detect that, that'd be as simple as [`/<\w+>/`](https://regexr.com/4157k). That would tell you if it contained `` if you wanted to not match this then just negate the result – Liam Oct 12 '18 at 15:53
  • @Liam Thank you – JanT Oct 12 '18 at 17:45

1 Answers1

2

Use:

<[^>]+>

Then negate the result.