I have the following string in several places throughout a massive HTML file: <div class="author">Some Author's Name</div>. I want to replace that with <author>Some Author's Name</author> and obviously adjust the corresponding CSS classes.
Is it possible to do that in a single Find and Replace in Xcode 6.1 without having to go through line by line?
I recommend you this article replace with regex in XCode.
Use the regex <div class="author">(.*)</div> to find your entities and replace with <author>$1 </author>
Related
I'm using VSCode for html editing. In VSCode it's very easy to select same occurences of a piece of code. What i need is selecting all ocuurances of an html attribute (like class, aria-label, etc.) with different values. Here's an example:
I want to select all "aria-label" occurences with the values included. So these will be selected:
aria-label="Apple"
aria-label="Oranges"
aria-label="Multiple Fruit Names"
aria-label=""
...
Is there a way to do that in VSCode?
I understood that regex knowledge essential so for last couple of days i studied Regex101, this is what worked for me on this question.
aria-[a-zA-Z]*="[A-Za-z\s]*"
You could use a regex for that:
^aria-label="[^"]*"
Explanation:
'^' ... matches newline
'aria-label=' ... that's your "search word"
'[^"]' ... any character
'*' ... zero or more occurrences of stuff within the group
Don't forget to enable regex search in search dialog (see below):
This is a good starting point to grasp the regex magic: https://en.wikipedia.org/wiki/Regular_expression#Basic_concepts .
what syntax of markdown do I need to write the api like below.
the html code is below:
link
<dl class="function">
<dt id="create_bootstrap_script">
<code class="descname">create_bootstrap_script</code><span class="sig-paren">(</span><em>extra_text</em><span class="sig-paren">)</span><a class="headerlink" href="#create_bootstrap_script" title="Permalink to this definition">ΒΆ</a></dt>
<dd><p>Creates a bootstrap script from <code class="docutils literal"><span class="pre">extra_text</span></code>, which is like
this script but with extend_parser, adjust_options, and after_install hooks.</p>
</dd></dl>
<p>This returns a string that (written to disk of course) can be used
as a bootstrap script with your own customizations. The script
will be the standard virtualenv.py script, with your extra text
added (your extra text should be Python code).</p>
<p>If you include these functions, they will be called:</p>
I've tried to use syntax like this, but turn out to be just like but not the same.
Orange(a, b)
: The fruit of an evergreen tree of the genus Citrus.
Every answer will be appreciated.
In the first example the dt is a codespan which has had syntax highlighting applied.
In the second example, the dt only contains plain text. You can get closer by using a code span as well:
`Orange(a, b)`
: The fruit of an evergreen tree of the genus Citrus.
Notice that the first line is wrapped in backticks (`) which makes it a code span. Of course, you still need syntax highlighting to get an exact match, but MkDocs does not currently support syntax highlighting for code spans, only code blocks. Presumably the virtualenv docs were built using Sphinx rather than MkDocs. While MkDocs comes close to matching Sphinx in looks, it does not match feature for feature and this is one of the differences. That said, it may be possible with a custom theme and/or using some custom Markdown Extensions.
I have a HTML Table of Contents page containing list of book chapters with hyperlinks:
Multimedia Implementation<br/>
Table of Contents<br/>
About the Author<br/>
About the Technical Reviewers<br/>
Acknowledgments<br/>
Part I: Introduction and Overview<br/>
Chapter 1. Technical Overview<br/>
...
I want create NCX file for a Kindle book which must contain details as follows:
<navPoint id="n1" playOrder="1">
<navLabel>
<text>Multimedia Implementation</text>
</navLabel>
<content src="final/main.html"/>
</navPoint>
<navPoint id="n2" playOrder="2">
<navLabel>
<text>Table of Contents</text>
</navLabel>
<content src="final/toc.html"/>
</navPoint>
<navPoint id="n3" playOrder="3">
<navLabel>
<text>About the Author</text>
</navLabel>
<content src="final/pref01.html"/>
</navPoint>
...
I'm using Notepad++: is it possible automate this process with regular expression?
You cannot do everything using regex.. you can split the problem into two parts..
generate strings like <navPoint id="n1" playOrder="1"> using program logic (increment variable)
remaining you can do with regex
Use the following regex to match:
<a\shref="([^"]*)">([^<]*)<\/a><br\/>
And replace with:
(generated string)<navLabel>\n<text>\2</text>\n<content src="\1"/>\n</navPoint>
See DEMO
Yes, it is possibly to replace the links with <navpoint> tags. The only thing I found no solution for is the incremental numbering of the <navpoint> attributes id and playOrder...
The following regex will do most of the work:
/^<a[^>]*href="([^"]+)"[^>]*([^<]+).*$/gm
substitute with:
<navpoint id="n" playOrder="">\n<navLabel><text>$2</text></navLabel>\n<content src="$1" />\n</navpoint>\n
Regex details
/^<a .. only parse lines that start with an `<a` tag
.*href=" .. find the first occurance of `href="`
([^"]+) .. capture the text and stop when a " is found
"[^>]*> .. find the end of the <a> tag
([^<]+) .. capture the text and stop when a < is found (i.e. the </a> tag)
.*$/ .. continue to end of the line
gm .. search the whole string and parse each line individually
More detailled (but also more confusing) explanation is here:
https://regex101.com/r/gA0yJ2/1
This link also demonstrates how the regex is working. You can test changes there if you like
I am trying to find all <br> instances in the following string, but only in the "categories" class:
<td>bla<br>bla</td><td class="categories">cat1<br>cat2<br>cat3</td>
I am realy new to regex, and this is what I tried so far, but it only finds the first <br> after cat1 and takes the whole part in front of it in the result as well...
(?>categories">).*?<br>
EDIT: I want to find all <br> occurences to replace them with a comma. For the moment I'm using a text editor (Sublime Text) to achieve this...
Why would you want to use regex? What are you trying to validate?
http://en.wikipedia.org/wiki/Regular_expression
If you want to find html elements using class variables then you want to look into javascript or jquery
http://api.jquery.com/class-selector/
Hope that helps a bit
I'm using TextMate to edit a project that I'm doing(HTML files) and I have some <div> tags assigned with the class=navigation property, but I need to change this <div>'s for a new design that I'm planning, but they are much(about 47 results if I search for class=navigation).
So I need a regular expression to match the entire line that this property is found, but which is it?
I'm not a regex expert, but I would think that ^.*class=navigation.*$ would work.