line-breaks

regex pattern that matches the string at the end of a string but is not followed by line break

大兔子大兔子 提交于 2019-11-28 05:40:27
问题 I use a regex pattern i preg_match php function. The pattern is let's say '/abc$/' . It matches both strings: 'abc' and 'abc ' The second one has the line break at its end. What would be the pattern that matches only this first string? 'abc' 回答1: The reason why /abc$/ matches both "abc\n" and "abc" is that $ matches the location at the end of the string, or (even without /m modifier) the position before the newline that is at the end of the string. You need the following regex: /abc\z/ where

Unix newlines to windows newlines (on Windows)

假装没事ソ 提交于 2019-11-28 05:21:21
Does anyone know of a way (say Powershell, or a tool) in Windows that can recurse over a directory and convert any unix files to windows files. I'd be perfectly happy with a way in Powershell to at least detect a unix file. It's easy do this for one single file, but I'm after something a bit more scalable (hence leaning towards a Powershellish solution). Here is the pure PowerShell way if you are interested. Finding files with atleast one UNIX line ending (PowerShell v1): dir * -inc *.txt | %{ if (gc $_.FullName -delim "`0" | Select-String "[^`r]`n") {$_} } Here is how you find and covert UNIX

Why doesn't $ in .NET multiline regular expressions match CRLF?

为君一笑 提交于 2019-11-28 04:53:28
I have noticed the following: var b1 = Regex.IsMatch("Line1\nLine2", "Line1$", RegexOptions.Multiline); // true var b2 = Regex.IsMatch("Line1\r\nLine2", "Line1$", RegexOptions.Multiline); // false I'm confused. The documentation of RegexOptions says: Multiline : Multiline mode. Changes the meaning of ^ and $ so they match at the beginning and end, respectively, of any line, and not just the beginning and end of the entire string. Since C# and VB.NET are mainly used in the Windows world, I would guess that most files processed by .NET applications use CRLF linebreaks ( \r\n ) rather than LF

Do browsers send “\\r\\n” or “\\n” or does it depend on the browser?

…衆ロ難τιáo~ 提交于 2019-11-28 04:36:19
This question has bothered me for a million years... whenever I create a website with a textarea that allows multi-line (such as a "Bio" for a user's profile) I always end up writing the following paranoid code: // C# code sample... bio = bio.Replace("\r\n", "\n").Replace("\r", "\n"); bio = Regex.Replace(@"\n{2,}", "\n\n"); So, what do browsers send up for a <textarea name="Bio"></textarea> if it has multiple lines? The HTTP and MIME specs specify that header lines must end with \r\n, but they aren't clear (some would argue that it isn't clear if they are clear) about what to do with the

How to print a linebreak in a python function?

╄→гoц情女王★ 提交于 2019-11-28 04:02:32
I have a list of strings in my code; A = ['a1', 'a2', 'a3' ...] B = ['b1', 'b2', 'b3' ...] and I want to print them separated by a linebreak, like this: >a1 b1 >a2 b2 >a3 b3 I've tried: print '>' + A + '/n' + B But /n isn't recognized like a line break. Winston Ewert You have your slash backwards, it should be "\n" The newline character is actually '\n' . for pair in zip(A, B): print ">"+'\n'.join(pair) >>> A = ['a1', 'a2', 'a3'] >>> B = ['b1', 'b2', 'b3'] >>> for x in A: for i in B: print ">" + x + "\n" + i Outputs: >a1 b1 >a1 b2 >a1 b3 >a2 b1 >a2 b2 >a2 b3 >a3 b1 >a3 b2 >a3 b3 Notice that

Removing line break powershell

喜你入骨 提交于 2019-11-28 03:34:30
问题 I am having an issue with a line break in my data. The array was made with an out-string followed by -split. If you want to see that part of the script let me know. foreach ($item in $array) { "_"+$item+"_" } Output: _ itemname_ Desired Output: itemname I've tried inserting: $item.replace('`','') Without any change. Any ideas? 回答1: Okay, I think this should work. I was under the impression you wanted those underscores in the result. $array -replace "`n|`r" 回答2: By default, 'Get-Content'

How to insert newline in string literal?

ぃ、小莉子 提交于 2019-11-28 03:02:52
In .NET I can provide both \r or \n string literals, but there is a way to insert something like "new line" special character like Environment.NewLine static property? Jon Skeet Well, simple options are: string.Format : string x = string.Format("first line{0}second line", Environment.NewLine); String concatenation: string x = "first line" + Environment.NewLine + "second line"; String interpolation (in C#6 and above): string x = $"first line{Environment.NewLine}second line"; You could also use \n everywhere, and replace: string x = "first line\nsecond line\nthird line".Replace("\n", Environment

See line breaks and carriage returns in editor

早过忘川 提交于 2019-11-28 02:53:11
Does anyone know of a text editor on Linux that allows me to see line breaks and carriage returns? Does Vim support this feature? jay.lee :set list in Vim will show whitespace. End of lines show as ' $ ' and carriage returns usually show as ' ^M '. To disagree with the official answer: :set list will not show ^M characters (CRs). Supplying the -b option to vi/vim will work. Or, once vim is loaded, type :e ++ff=unix . Larry K VI shows newlines (LF character, code x0A ) by showing the subsequent text on the next line. Use the -b switch for binary mode. Eg vi -b filename or vim -b filename -- .

Removing redundant line breaks with regular expressions

廉价感情. 提交于 2019-11-28 00:53:57
I'm developing a single serving site in PHP that simply displays messages that are posted by visitors (ideally surrounding the topic of the website). Anyone can post up to three messages an hour. Since the website will only be one page, I'd like to control the vertical length of each message. However, I do want to at least partially preserve line breaks in the original message. A compromise would be to allow for two line breaks, but if there are more than two, then replace them with a total of two line breaks in a row. Stack Overflow implements this. For example: "Porcupines\nare\n\n\n

Regular expression: how to match a string containing “\\n” (newline)?

最后都变了- 提交于 2019-11-27 23:51:23
I'm trying to dump data from a SQL export file with regular expression. To match the field of post content, I use ' (?P<content>.*?) '. It works fine most of the time, but if the field contains the string of '\n' the regular expression wouldn't match. How can I modify the regular expression to match them? Thanks! Example(I'm using Python): >>> re.findall("'(?P<content>.*?)'","'<p>something, something else</p>'") ['<p>something, something else</p>'] >>> re.findall("'(?P<content>.*?)'","'<p>something, \n something else</p>'") [] P.S. Seemingly all strings with '\' in the front are treated as