Can someone please help me in finding a regex that checks in a string if it contains one of the following html break tags?
<br>, <br/>, <br >, <br />
If you want to indicate a line break when you construct your RegEx, use the sequence “\r\n”. Whether or not you will have line breaks in your expression depends on what you are trying to match. Line breaks can be useful “anchors” that define where some pattern occurs in relation to the beginning or end of a line.
$ means "Match the end of the string" (the position after the last character in the string).
Use the test() method to check if a regular expression matches an entire string, e.g. /^hello$/. test(str) . The caret ^ and dollar sign $ match the beginning and end of the string. The test method returns true if the regex matches the entire string, and false otherwise.
This answer is not useful. Show activity on this post. [] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9.
<br\s*/?>
and you should make that case-insensitive (depends on the language or tool you are using). If you want to be that strict to really allow only the four versions you posted (and not multiple spaces), cadrian's version is what you are looking for: <br ?/?>
try this out: "<br ?/?>"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With