I'm building up my first Grunt project and one of my tasks is introducing blank lines into the beginning of my output html files. I'd like to remove them.
I found grunt-line-remover but it requires me to list each html file separately, and I'd rather point it to a directory. (and I don't have time right now to figure out how to tweak the code to do that.)
I then found grunt-text-replace which supports file name pattern matching, but I can't figure out the Regex for finding a blank line in an html file.
I tried
/\n/g
but that replaces every new line whereas I'd like to just replace the empty lines. Really, I just want to replace the beginning blank lines, but if it removes every blank line that's fine.
Any help would be appreciated
If you want to remove empty space Try using a regex of [\r\n]{2,}
Instead of looking for newlines, you can look for empty lines with the regex
/^\s*$/gm
It should give you empty lines as well as lines containing spaces only.
Related
I know that every syntax highlight in notepad++ is based on regular expressions configured for the current language, but where do notepad++ stores the files relative to these regexes?
In my case, I want to highlight javascript comments that are placed following (or inside, using double slashes, if you prefer) comments in a different way of standard comments, like that:
product(); //just a comment about what is being made on the execution part of the line
//sum(); //comment formatted the same way as the executional part, which is also commented
That is because I want to distinguish these comments from commented execution code. The commented execution line is '//sum();' in this case, as '//comment...' is the comment that was commented and is following the first comment. Both are gray, but I want notepad++ to use another color to show everything that is after the second pair of slashes.
Anybody can also help me in building this regex?
Let's say the structure of the page URL is http://string.static.com/*
string may vary but will only consist of any combination of alphanumeric characters and dashes.
static.com is self-explanatory.
* could be anyting containing letters, numbers, /,:,? and similar characters, so basically there can be directories and parameters as well.
What I'm trying to achieve is this:
The bookmarklet should replace everyting after .com/... so the url becomes http://string.static.com/archive
I've created two (very similar) JS bookmarklets so far but I can't wrap my head around this one. It should be fairly simple but I haven't had any luck. Thanks in advance.
I wrote a trivial google apps script that runs thru a google document to divide pieces of text. Now, the text that my code need to divide seems to include newlines.
My problem is that I just don't understand how to remove these programmatically (I tried: mydoc.replaceText("/\n/",""); and mydoc.replaceText(/(\r\n|\n|\r)/gm,""); plus other similar variations with no success.
I can't comment but maybe something like this works for you? replaces whitespace with single spaces
mydoc.replaceText("/\s/"," ");
So, I've basically got this page, and when I run it through the W3C Validator, it's not validating. Does anyone know why?
http://jsfiddle.net/BcrW9/1/
Thank you!
It was your jquery include.
Possibly some sort of encoding issue. It happens occasionally when copying code (like a script block) from another site. I think OSX preserves the original encoding while windows converts clipboard text to some standard encoding. Anyways, this works. I simply copied the second script tag, pasted it, changed the src value, and removed the one you copied from some place else. http://jsfiddle.net/BcrW9/2/
PS -- Please confirm or deny your use of OSX in a comment. This happens to me in OSX all the time. Never had this problem in Windows.
Really just expanding on MicronXD's answer. The character immediately following the <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> text but before the line break is U+200C ZERO WIDTH NON-JOINER. (I needed a hex editor to see this).
To an HTML5 parser, this is a normal text character, so it assumes that the head element has finished and the body element has started (remember that the end head and start body tags are both optional) so it infers these tags, creates the body element and adds the stray character to that.
Then the validator parser sees the end head tag and the start body tag and reports them as errors because the parser is already in the "In body" state.
To get rid of the stray character, just select and delete the characters between the two script lines including the > at the end of the first script line and the < at the start of the second script line, then retype the characters you need.
I have a few strings and I would like to insert some line breaks into them at certain points.
I figured out a few of the logistics but as a whole I can't seem to crack this problem, probably because I have limited experience with regex.
Basically I have a long string of XML tags that is all on one line. I want to add line breaks at certain points to get the data more formatted and looking nice. I am using CodeMirror to display this data on a webpage but for some reason its all on line #1.
So I need to go from something like this:
<Sample><Name></Name><PhoneNumber><AreaCode></AreaCode><Number></Number></PhoneNumber></Sample>
To something like this:
<Sample>
<Name></Name>
<PhoneNumber>
<AreaCode></AreaCode>
<Number></Number>
</PhoneNumber>
</Sample>
CodeMirror will take care of the rest of the formatting all I need to do is insert the line breaks in the right spot using regex or a loop of some sort. The Tags will or can change so I am guessing regex has to be used.
I have had success inserting line breaks with \n and 
 but can't seem to get regex to detect the proper locations.
Any help would be greatly appreciated. Thanks.
UPDATE
I overlooked this but the brackets are in fact being sent as < and >
So example tag would look like:
<PhoneNumber>
or
</PhoneNumber>
So basically need to insert a \n after every > that is a closing tag or a beginning tag that contains children tags.
There be dragons here.
I'd like to point you to a very similar question answered awhile ago that does a good job of explaining why you should NOT try to parse XML yourself unless you REALLY know what you're doing.
Use an XML deserializer if you want to get nice line breaks and that sort of thing.
Try this regex pattern:
>\s*<(?!/)
Replacement string : >\n<
UPDATE:
>\s*<(?!/)