Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have the following expression to validate a specific tag:
<TAG(:([^:>\\s]*))?>
This pattern should be valid for: <TAG:abc>, <TAG:dfg>, etc
<TAG:abc>
<TAG:dfg>
How to make this expression be invalid in this case: <TAG:hij>k> (k> = invalid closing tag).
<TAG:hij>k>
<TAG(:([^:>\\s]*))?>(?=\s|$)
\\s
s
Just use a lookahead after to your regex to ensure that the tag must be followed by a space or end of the line anchor.
OR
<TAG(:([^:>\s]*))?>(?=\s|$)
DEMO
Add a comment
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
<TAG(:([^:>\\s]*))?>(?=\s|$)is correct! Thank you\\sinside a character class would mean a literal \ and an literalscharacter. It wouldn't match a space character.