') This works gre...">All geek questions in one placeRegular expression for strip \ r and \ n or \ r \ nI use the following regex to create newline tags:str.gsub("\r\n", '<br>') This works great on the desktop. there is only \ n on the text of the iphone, it does not have \ r.How can I create regex support? \ r \ n or just \ n?thanks+6ruby regexAnapprentice Feb 02 '12 at 5:36source share5 answers\r\n|\r|\nThis regex will also allow you to support Macs that only use \r as the end of a line. Since regular expressions are greedy, they will match \r\n , and not separate ones, if possible.+8Niet the dark absol Feb 02 '12 at 5:40source shareI think, str.gsub(/\r?\n/, '<br>') must do the job+12barley Feb 02 '12 at 5:40source shareoperator ? accepts 0 or one of the previous element, so \r?\n should accept \r or \n or \r\n+1smitec Feb 02 '12 at 5:39source shareThis is probably the easiest way: str.gsub(/\R/, '<br>') /\R/ works for Mac / Linux / Windows and includes more exotic unicode strings.+1Eric Duminil Dec 19 '16 at 19:51source share\r?\n|\r\r?\n will match \n or \r\n .\r will only match \r .This should work for Windows \ Mac \ Linux EOL.0Moe nasser Apr 22 '16 at 15:37source shareSource: https://habr.com/ru/post/907458/More articles:Creating a table with the current date plus 30 days after the current date - databaseword count of each line in script - bashConvert searchable PDF to PDF without search - pdfWhere to store static files, such as html / css / javascript, in a berth project? - javaCannot force Intellij to use AspectJ compiler - javaRecursive concatenation of parent elements - sqlSQL statement to combine categories from a hierarchical structure into a single row - sql-serverHow to assign an object function to a variable? - phpPrevent Cassandra from dumping hprof files - javaiOS: How to implement handwriting recognition? - iosAll Articles
I use the following regex to create newline tags:
str.gsub("\r\n", '<br>')
This works great on the desktop. there is only \ n on the text of the iphone, it does not have \ r.
How can I create regex support? \ r \ n or just \ n?
thanks
\r\n|\r|\n
This regex will also allow you to support Macs that only use \r as the end of a line. Since regular expressions are greedy, they will match \r\n , and not separate ones, if possible.
\r
\r\n
I think,
str.gsub(/\r?\n/, '<br>')
must do the job
operator ? accepts 0 or one of the previous element, so \r?\n should accept \r or \n or \r\n
?
\r?\n
\r or \n or \r\n
This is probably the easiest way:
str.gsub(/\R/, '<br>')
/\R/ works for Mac / Linux / Windows and includes more exotic unicode strings.
/\R/
\r?\n|\r
\r?\n will match \n or \r\n .
\n
\r will only match \r .
This should work for Windows \ Mac \ Linux EOL.
Source: https://habr.com/ru/post/907458/More articles:Creating a table with the current date plus 30 days after the current date - databaseword count of each line in script - bashConvert searchable PDF to PDF without search - pdfWhere to store static files, such as html / css / javascript, in a berth project? - javaCannot force Intellij to use AspectJ compiler - javaRecursive concatenation of parent elements - sqlSQL statement to combine categories from a hierarchical structure into a single row - sql-serverHow to assign an object function to a variable? - phpPrevent Cassandra from dumping hprof files - javaiOS: How to implement handwriting recognition? - iosAll Articles