I'm using sublime text 2 editor. I would like to remove all other texts except the name tag value.
Here is an example
<div class="control-group">
<label class="control-label" for="c_email">Email (required)</label>
<div class="controls">
<input type="text" name="c_email" value="">
</div>
</div>
In the above code I would like to keep only the name tag value. To match all name tags I use regex like this
name="(.+?)"
It matches all name tags. But when I replace it with $1 it only replaces name="c_email" with c_email
Can someone help me to erase all other texts?
Thanks
you can do it like that:
find: [\s\S]*?name="(.+?)"[\s\S]*
replace: $1
if you want to limit deletion to your target div:
find: <div class="control-group"[\s\S]*?name="(.+?)"[\s\S]*?</div>\s*</div>
replace: $1
Related
Have a small issue and wondering if some one can help me out.
I have a text search box like this that
<form class="navbar-form navbar-left" role="search" action="/library/search/">
<div class="form-group" style="display:inline;">
<div class="input-group">
<input class="form-control" id="q" name="P" type="text" placeholder="Book Search"">
<span class="input-group-btn">
<button class="btn btn-primary" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</span>
</div>
</div>
</form>
When I type in a word and hit submit a URL is generated as follows,
http://127.0.0.1:8000/library/search/?P=Harry+Potter
In the URLs.py I have something like this
url(r'^search/(?P<search_result>[\w|\W.#+-]+)/$', views.search_view, name='search_view')
However the above url is not being matched by the regex statement. If I manually remove the ?P= from the url it works fine.
I have tried some of the following combination and they didn't work either
url(r'^search/(?P(.*)<search_result>[\w|\W.#+-]+)/$', views.search_view, name='search_view')
Any idea what it could be ?
Thanks
You've misunderstood what ?P means in a regex. It states that the group is a named group, which is captured and sent to a view by a keyword argument. The URL that would satisfy that regex is like this:
/library/search/harrypotter/
But that's not at all what you want from a search; you want something like the one you have created, ie library/search/?P=harry+potter. For that you just want a URL without parameters:
r'^search/$'
and get the data in the view:
query = request.GET['p']
although you probably want to use q rather than p.
I'm trying to replace a common theme used in hundreds of pages in my project:
<div id="PageTitle"> (Page title as a string) </div>
And the title varies each page. I want to replace it with
<div class="row">
<div class="col-md-12 col-sm-12">
<h3><?= $pageTitle?></h3>
</div>
</div>
I've tried searching with <div id="PageTitle">/^\w+$/</div>, and <div id="PageTitle">"^[a-zA-Z0-9_]*$"</div> with no luck. Any ideas?
You are almost there. Looks like you got the pattern from somewhere else. ^ and $ are starting and ending anchors so they match with the start and end of an input so you should probably get rid of them.
Next if your page title is only going to contain alphanumeric characters (no spaces too) then \w is fine, else you might want to use . instead.
<div id="PageTitle">\w+<\/div>
For a title containing any character:
<div id="PageTitle">.+?<\/div>
Here's a demo
Hope this helps!
Try this one as well, I think its pretty strict:
<div id="PageTitle">(?:(?!<\/div>).)+<\/div>
Or even:
<div id="PageTitle">[\s\S]*?<\/div>
How can I write a regular expression to find the third div class name in a group div? So in the instance below, I'd like to find clsA3
<div class="clsA">
<div class=clsA1">blah</div>
<div class=clsA2">blah</div>
<div class=clsA3">blah</div>
</div>
I'm trying to use Visual Studio 2013 Search and Replace using Regular Expression option. The purpose of this task is one-time maintenance task.
Works with VS2010. Not sure if VS2013 does normal regex yet.
Find:
{\<div class=[^>]*\>[ \n]*(\<div class=[^>]*\>[^<]*\</div\>[ \n]*)^2\<div class="#}[^">]+{"#\>[^<]*\</div\>[ \n]*\</div\>}
Replace:
\1Hello World\2
Output:
<div class="clsA">
<div class=clsA1">blah</div>
<div class=clsA2">blah</div>
<div class=Hello World">blah</div>
</div>
I have some html files that I want to find them if these words:
id="s"
doesn't have this tag before them
<div
And if it doesn't, the regex adds it, so the result be:
<div id="s"
And leaves everything before the div or after id="s" as is.
Given that:
the id="s" could have spaces or tabs before it
it has some words after it
the missing "< div" could be before it with a line or in the same line before the id="s"
The simplest approach would probably be to search for all occurrences of either <div id="s" or id="s" that follows any whitespace and replace either one with <div id="s". (That is, rather than looking for id="s" then looking backwards for <div, just include <div in the search.)
Find what: <div\s*id="s"|\s*id="s"
Replace with: <div id="s"
Before:
test
test <div
id="s"
test
id="s"
test <div id="s"
test id="s"
<div id="s"
test id="s"
<div id="s"
After Replace all:
test
test <div id="s"
test<div id="s"
test <div id="s"
test<div id="s"
<div id="s"
test<div id="s"
<div id="s"
You can either add leading whitespace to the search and replace fields, or do another pass to put however much space you need back between test<div id="s".
im using pcre RegExp engine , and i have string that looks like this :
<h3 class="description">Description</h3> <div class="wrapper"> dddsome string blah blahddssssseeeee <div class="empty"> </div></div> </div> </div>
and regexp that works fine and cpture the string "dddsome string blah blahddssssseeeee"
that looks like this :
<\s*h3\s*class="*.+?"\s*>.*?</\s*h3>.+?<\s*div.+?class\s*="wrapper"\s*>(.+?)<\s*div\s*class="empty">
now some time i have the Almost the the same pattern of string that looks like this not the div class="aplus" tag , when this tag appear i want the regexp above to fail to match the all string .
<h3 class="description">Description</h3> <div class="wrapper"> <div class="aplus"> dddsome string blah blahddssssseeeee <div class="empty"> </div></div> </div>
try this
<div.*>(.*)<div.*>
but use beautiful-soup for easy better web scraping