Use the global flag.
str.replace(/\n/g, '<br />');
More Related Contents:
- Split a string between special characters [closed]
- Not able to get Regular Expression in javascript
- Find String and extract with next String
- Regex to replace multiple spaces with a single space
- Check for special characters in string
- Template literal inside of the RegEx
- JavaScript regular expressions and sub-matches
- RegEx for match/replacing JavaScript comments (both multiline and inline)
- Restricting character length in a regular expression
- JavaScript regex pattern concatenate with variable
- javascript regular expression to check for IP addresses
- JavaScript regex: Positive lookbehind alternative (for Safari and other browsers that do not support lookbehinds)
- Regex negative lookbehind not valid in JavaScript [duplicate]
- Regular Expression to reformat a US phone number in Javascript
- Javascript split string on space or on quotes to array
- Regex to remove spaces between ‘[‘ and ‘]’
- Regex and ISO8601 formatted DateTime [duplicate]
- RegEx – Get All Characters After Last Slash in URL
- JSLint “insecure ^” in regular expression
- Converting Date and Time To Unix Timestamp
- JavaScript – string regex backreferences
- Regular Expression for accurate word-count using JavaScript
- JavaScript replace \n with [duplicate]
- What does the forward slash mean within a JavaScript regular expression?
- REGEX: Capture Filename from URL without file extension
- Only numbers. Input number in React
- Extract parameter value from url using regular expressions
- Javascript – regex – word boundary (\b) issue
- Javascript Regular Expression for rgb values
- How to escape backslash in JavaScript?