I am trying to remove trailing whitespace including \r and \n at the end of aspx files by using Find and Replace using the pattern
\s+(?!.)
trying to replace whitespace followed by nothing with nothing.
The result is that everything will come on the same line.
Why?
I also tried \s+$ with the same result.
You may add a negative lookahead to the end of your current pattern:
(\s+\r?\n)+$(?!.)
This will ensure that only final lines with whitespace only are matched. See the demo here.
Related
I'm not sure whether I couldn't find the correct way or this is a bug.
I wanted to check some reference manual but there doesn't seem to be one.
In Jupyter's Find and Replace screen, there's an icon .* to check when I want to use regex.
Mostly it works fine, but if I try to match a line break (\n), it does not match it unless it is that very character. For example, I want to match every line that doesn't end with , and join that line to the next one. I'd match [^,]\n and replace with ,, which would remove the line break. I could try [^,]$, but replacing this wouldn't remove the line break.
How do I do this?
There are a lot of variants of the new-line character.
E.g.: \r or \n
Regex Pattern
Anyway, here is the pattern using lookahead to check if there is a comma before, and the variants of new-line character.
(?<!,)(\r?(\n|\r))
Regex Demo
I'm trying to write Regex to find lines in a files where commands are not using absolute paths. Unfortunately, there are spacing issues with these lines.
// PATHS
pathmunge /absolute/path
pathmunge ~not/absolute/path
pathmunge /absolute/path
// matches
pathmunge ~not/absolute/path
My expression matches the lines where there are spaces at the beginning and before pathmunge string, but it doesn't find the lines with variable-length whitespace but without a "/" as the next non-whitespace character.
So far, I have:
^(?=\s+pathmunge)\s+(?!\/).*$
Any help is appreciated.
For a regex, I would do:
^(?:[[:blank:]]*pathmunge[[:blank:]]+([^\s\/].*$))
Demo
The key element is the [^\s\/] which matches a single character other than a horizontal space or a \n or / start of any absolute path.
Remove the lookahead and make the space possessive:
^\s*pathmunge\s++(?!\/).*$
Demo & explanation
I want to search for the following regular expression
^[ ]*,$
in the following text :
,[LF]
,[LF]
My problem is that Delphi finds the expression, but the matched text doesn't include the LF.
Effectively I want to removes the lines from my source code.
I'am using TPerlRegEx with delphiXe8
In the example [LF] is the linefeed ($0D $0A)
I Tested several flags combinaisons in TPerlRegExOptions
This works perfectly in SublimeText 3
What am I missing ?
If you are using a PCRE regex, you can match zero or more spaces at the stsart of a line followed with a comma followed with a newline sequence with
(?m)^[ ]*,\R
See the regex demo. Note that (?m) is a multiline modifier making ^ match a location at the beginning of a line (after \n). \R matches any newline sequence.
Add a ? after \R to also match the last line in the text that has no newline sequence at the end.
I am working on a vbs regexp that will detect a tag which contains text and a CRLF character before closing tag.
I am currently using \w+[:;?!.,""\)\]-~]*(\s)*(\r\n\s*)(<\/.*>)
Looking from the end of the expression, I am matching any closing tag, CRLF plus optionally blank spaces, an optional spaces before CRLF and it should optionally match any other visible non-letter character which occurs after any word.
This is to match things like
myword! CRLF</tag>
mywordCRLF</tag>
myword CRLF</tag>
myword...CRLF </tag>
etc.
However, I do not want to match below, as I need to detect tags containing TEXT and linebreaks.
</otherclosingtag> CRLF </tag>
I am concerned about the \w+[:;?!.,""\)\]-~]* bit as it doesn't look right to me, as I would need to insert quite a large number of characters here.
I tried replacing it with \S, \W but they all seem to match CRLF characters as well.
Any ideas?
Cheers!
How about using non-greedy modifier:
\w+\W*?\r\n\s*(<\/.*>)
or
\w+[^\r\n]*\r\n\s*(<\/.*>)
The solution that I used:
\w+[^\r\n<>]*(\r\n\s*)(<\/.*>)
It matches a word (so not ) then anything that is not the CR, LF or > (so it doesn't match openingtag> CRLF</closingtag>)
This is a modified version of what M42 has proposed, I had added <> to make sure we won't match a tag.
Thanks for suggestions!
Try this:
^.*[\n\t\s]*</.*>$ --> BAD
^.*[\r\n\t\s]*</.*>$
I have a .org file with lines of this sort:
*
http://en.wikipedia.org/wiki/Qibla Qibla - Wikipedia, the free
as you can see, an asterisk, followed by newline, followed by URL, followed by one space, and then some extraneous useless text that i want to get rid of.
i would like to format this file to this structure:
*
http://en.wikipedia.org/wiki/Qibla
or, strip all the characters after the end of the URL while maintaining the rest of the structure.
how can i do this in emacs?
Assuming you're doing this interactively with query-replace-regexp, try using this regex to string the junk off the end of the URLS:
^\(http[^ ]+\).*$
Replacement:
\1
You can get rid of the asterisks easily enough, use this regex and replace with nothing:
*^J
Use control-Q followed by control-J to enter the newline.
Edit: Or, to do it in one, replace
*^J\(http[^ ]+\) .*^J
With
\1^J
Where ^J is a literal newline inserted by typing control-Q followed by control-J.