I need to change all:
<label for="*">
into
<label for="*" class="inline checkbox">
But it turns out all my <label for="XXXXXX"> were turned into <label for="*" class="inline checkbox">. Yes, the * is literally kept as a string not as a wildcard.
How come the wildcard is only effective in Find not in Replace? What should I input in the Replace string?
The accepted answer is offered in other places as well but didn't work for me.
I had to use (.*) in the Find and $1 in the Replace.
I'm not sure if there is a way to do this with wildcards, but you can get it done using regular expressions:
In the Find and Replace dialog box, below Find Options, check
Use: and from the dropdown select Regular expressions.
In the text box for Find What, type: \<label for="{.*}"\>
In the text box for Replace with, type: <label for="\1"
class="inline checkbox">
Notes:
I escaped < and > with \ because they are special characters.
.* will match any string.
In the replace text, \1 will replace with the string found between
the {} in the find expression.
Also, if you click the arrows next to the find and replace text boxes, you will find more info about the special characters.
Related
I have this line of HTML
<input id="checkVSC" type="checkbox" checked data-toggle="toggle" name="checkVSC"
data-onstyle="info" data-offstyle="default" data-size="small"
data-on="<i class='icon icon-checkmark'></i> VSC"
data-off="<i class='icon icon-line-plus'></i> VSC">
for the data-on it gives me the green squiggly line saying: "If the attribute value is enclosed in quotations marks, the quotation marks must match"
This isn't a major item, but when I do Ctrl-K Ctrl-D to re-format the lines of code to make them neat and pretty it adds a ">" to the data-on attribute.
<input id="checkVSC" type="checkbox" checked data-toggle="toggle" name="checkVSC"
data-onstyle="info" data-offstyle="default" data-size="small"
**data-on="><i class='icon icon-checkmark'></i> VSC"**
data-off="<i class='icon icon-line-plus'></i> VSC">
Any one have any idea as to what is going on here and why it is doing what it is doing?
VS gets fooled because your HTML is invalid.
Attribute strings should be escaped:
data-on="<i class='icon icon-checkmark'></i> VSC"
data-off="<i class='icon icon-line-plus'></i> VSC">
To avoid such situations in the future You might try to:
enable HTML validation
try any online validator
Some other IDEs and text editors provide automatic validation and even automatic escaping as well.
I have this html snippet
<div id="overview">
<strong>some text</strong>
<br/>
some other text
<strong>more text</strong>
TEXT I NEED IS HERE
<div id="sub">...</div>
</div>
How can I get the text I am looking for (shown in caps)?
I tried this, I get an error message saying not able to locate the element.
"//div[#id='overview']/strong[position()=2]/following-sibling"
I tried this, I get the div with id=sub, but not the text (correctly so)
"//div[#id='overview']/*[preceding-sibling::strong[position()=2]]"
Is there anyway to get the text, other than doing some string matching or regex with contents of overview div?
Thanks.
following-sibling is the axis, you still need to specify the actual node (in your example the XPath processor is searching for an element named following-sibling). You separate the axis from the node with ::.
Try this:
//div[#id='overview']/strong[position()=2]/following-sibling::text()[1]
This specifies the first text node after the second strong in the div.
If you always want the text immediately preceding the <div id="sub"> then you could try
//div[#id='sub']/preceding-sibling::text()[1]
That would give you everything between the </strong> and the opening <div ..., i.e. the upper case text plus its leading and trailing new lines and whitespace.
I can find examples of surrounding a line but not surrounding and replacing, and I'm a bit new to Regex.
I'm trying to ease up my markdown, so that I do not need to add in html just to get it to center images.
With pandoc, I apparently need to surround and image with DIV tags to get it to be centered, right justified, or what ever.
Instead of typing that every time, I'd like to just preprocess my markdown with a ruby script and have ruby add in the DIV's for me.
So I can type:
center![](image.jpg)
and then run a ruby script that will change it to
<div class="center">
![](image.jpg)
</div>
I want the regex to find "center!" and get rid of the word "center" and surround the rest with DIV tags.
How would I accomplish this?
A little example using gsub:
s = "a\ncenter![](image.jpg)\nb\n"
puts s.gsub(/^center(.*)$/, "<div class=\"center\">\n\\1\n</div>")
Result is:
a
<div class="center">
![](image.jpg)
</div>
b
Should get you started. The (.*) captures the content after center, and \\1 adds it back into the replacement. In this example I assumed that the item was on a line by itself - ^ indicates the start of a line and $ indicates the end of a line. If that isn't the case, you'll need to determine what makes what your regex unique so that it doesn't replace any random usage of "center" in your text.
How to swap attributes ID and runat in all tags in my Visual Studio 2008 solution?
Was
<asp:Label ID="Label1" runat="server" />
became
<asp:Label runat="server" ID="Label1" />
In Find and Replace, enable Use of Regular expressions.
Find what:
ID="{[^\"]+}" runat="server"
Replace with:
runat="server" ID="\1"
Use {} to tag sub-expressions within regular expression. The meaning of find part is: find one or more characters that aren't quotation marks after ID=" and up to next quotation mark and tag it as sub-expression.
In replace, you use \1 to denote the first sub-expression found and that's the tag id.
Edit: Add a single space character in front of search and replace expressions, to avoid matching something like: ContentPlaceHolderID="MainContent" runat="server".
I find that sometimes, the value = "" is missing. So I am reverting to querying for the normalized inner Text.
<label><input type="radio" name="addThree">A Radio</label>
<label><input type="checkbox" name="hasPic"> A Checkbox </label>
Here are the xpath's respectively...Are these correct?
//label/input[normalize-space(text()) = "A Radio"]
//label/input[normalize-space(text()) = "A Checkbox"]
It should work in this case, but it is not the best way; better omit the parameter to normalize-space (which then makes it equivalent to . which is the concatenation of all text content of the input element). Using it the way you did may cause problems if there are multiple text nodes inside the input element, which may happen if you also have comments or processing instructions inside.