Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm using a simple pattern like this :
<input type="text" pattern="[a-z]{2}" required ../>
But it's never valid. It seems it didn't works.
I tested it in Firefox
Is there something to active or something like that ?
My template :
<section class="inscription">
<h1>Inscription</h1>
<form method="post" enctype="multipart/form-data">
<div class="formu-inscription">
<label for="nom"> Nom : </label> <br/><input type="text" id="nom" name="nom" value="{set_value('nom')}" pattern="[a-z]{2}" required /> <br />
{form_error('nom')}
/* others inputs */
For people using smarty template, you can do
pattern="[a-z]{literal}{2}{/literal}"
Looking at the rendered source code you posted as a comment on a now deleted answer you have
<input type="text" id="nom" name="nom" value="" pattern="[a-z]2" required />
This is not the pattern in your source that you posted in your question. It seems that you are using some unspecified templating system that is using the {} characters as field identifiers and is misinterpreting your pattern.
The result in your rendered page is the pattern [a-z]2, which will validate for a string like a2 or f2, but not a, or aa, a3 or anything longer.
Since you haven't specified what templating system you're using it's not possible to indicate how you might work around this. Possibly a pattern of [a-z]{{2}} might work.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a tonne of code like this in a massive file and I simply want to delete all divs with the qt class.
<div class="qt">
<div class="qy"> Standard Delivery</div>
<div class="qu">€1.95/$2.99</div>
</div>
<div class="qe" data-country="kw.svg">
<p class="qr"> Kuwait </p>
</div>
<div class="qt">
<div class="qy"> Standard Delivery</div>
<div class="qu">€1.95/$2.99</div>
<div class="qs"> Express Delivery</div>
<div class="qb">€2.95/$3.99</div>
</div>
<div class="qe" data-country="ml.svg">
<p class="qr"> Malawi </p>
</div>
I would like to select all divs with the qt class up to the matching closing div in VSC (find and replace). How would we go about doing that especially given there are a varying number of other </div> tags inside the div we want to select?
As I mentioned in the comments above, if your code is similarly formatted to that portion you showed, it becomes easier to do this with find/replace. For instance:
(^\s*<div class="qt">)[\s\S]*?(^\s*<\/div>\n) find and replace with nothing.
This form requires that your inner div's are one-liners like
<div class="qy"> Standard Delivery</div> where the entire element is on one-line.
See https://regex101.com/r/LxCr6k/1
If those inner div's are not necessarily one-liners, this is the simplest version I found that fits your data:
^\s*<div class="qt">[\s\S]*?<\/div>\n^\s*<\/div>\n
see https://regex101.com/r/LxCr6k/6
To explain this latter one:
^\s*<div class="qt"> find a qt class div
[\s\S]*?<\/div>\n^\s*<\/div>\n go, newlines or characters, until 2 consecutive <\/div>'s.
Now this version does require that of the 2 consecutive ending </div> tags following a qt class opener that the second represents the closing tag of the qt opening tag. So if your data could look like this:
<div class="qt">
<div class="qy"> Standard Delivery</div>
<div class="qu">€1.95/$2.99
<div class="qu">€1.95/$2.99</div> <= inner tag here
</div>
</div>
than these regexes won't work. Nested tags are notoriously "hard" to handle with a single regex. Only you know if your data allows this last regex to work. Your data as presented looks regular and simple enough to allow a regex approach to work.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to extract a specific word (that might change) which comes after a permanent expression. I want to extract the name Taldor in this code:
<h4 class="t-16 t-black t-normal">
<span class="visually-hidden">Company Name</span>
<span class="pv-entity__secondary-title">Taldor</span>
</h4>
For now I able to find <h4 class="t-16 t-black t-normal"> using this regex:
(?<=<h4 class="t-16 t-black t-normal">).*
Will be glad for any kind of advice.
I'd suggest you to use an HTML parsing library like Jsoup in Java or beautifulsoup in Python to parse HTML instead of using regex for this reason
Following is the kind of code that does the job for you,
String s = "<h4 class=\"t-16 t-black t-normal\">\r\n" +
" <span class=\"visually-hidden\">Company Name</span>\r\n" +
" <span class=\"pv-entity__secondary-title\">Taldor</span>\r\n" +
" </h4>";
Document doc = Jsoup.parse(s);
for (Element element : doc.getElementsByClass("pv-entity__secondary-title")) {
System.out.println(element.text());
break;
}
Prints,
Taldor
In worst case, if you are doing some quick and dirty work, you can do this temporary solution using regex but it is surely not recommended thing to do.
<span class="pv-entity__secondary-title">(.*?)<\/span>
Use this regex and capture your data from group1.
Demo
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have created a small form which includes something like name, mobile number, age field. All are text fields.
These values are stored in DB.
I want my template to pre-populate the form with values from DB (if exists). How can this be done?
My template code is as below:
<div>
<center><form action="/profilesettings/" method="post" enctype="multipart/form-data">{% csrf_token %}
{{form.as_p}}
<input type="submit" value="submit">
</form></center></div>
Currently, it displays form with empty field. Instead of empty fields, I would like them to show values which are fetched from DB.
check this example on django docs
article = Article.objects.get(pk=1)
article.headline
'My headline'
form = ArticleForm(instance=article)
form['headline'].value()
'Initial headline'
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am using shortcodes in WordPress. After each shortcode output (closing div) I got <br> (or <br />) tag.
trying to filter them out, but I don't know how. Generated HTML looks like
<div class="fullwidth"><!-- 1st shortcode-->
<div class="fullwidth-content">
<!-- 2nd shortcode-->
<div class="twocol-one"> content
</div><br>
</div><br>
<!-- 3rd shortcode-->
<div class="twocol-second"> content
</div><br>
<div class="clearboth"></div>
</div><br>
seems BR is newline from tinyMCE. And I don't want loooong shotcode lines.
I am trying to use preg_replace but i cannot create correct $pattern.
Can you help me?
my function
function replace_br($content) {
$rep = preg_replace("/<\/div>\s*<br\s*\/?>/i", "</div>",$content);
return $rep; }
add_filter('the_content', 'replace_br');
not working.
While using
$rep = preg_replace("/\s*<br\s*\/?>/i", "",$content); in function, all BRs are replaced.
Fine, but i want to replace only BRs after closing DIV tag.
str_replace("</div><br>", "</div>", $content); also not working.
What's wrong with my function?
No error returned.
You are doing it wrong in the first place, since you have to remove the tags.
You are doing it wrong because you're using regex for HTML (sometimes it's OKish).
Variation of regex you're using should suffice: Demo
You should really consider using DOMDocument or similar:
$html = <<<HTML
...
HTML;
$dom = new DOMDocument();
$dom->loadHTML($html);
$element = $dom->getElementsByTagName('br');
$remove = [];
foreach($element as $item){
$remove[] = $item;
}
foreach ($remove as $item) {
$item->parentNode->removeChild($item);
}
$html = $dom->saveHTML();
echo $html;
This would remove all of br, you would need to adjust the code work for your specs, but this should be a pointer.
this is an alternative way to use regex
in your case
/(?<=<\/div>)(<br[\s\/]?>)/mg
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to edit the Record2 but when I click the Edit button it always display the info of Record1. If I click any other Edit buttons it only display the info of Record1. How does it know which record I want to edit? Please help. Thank you.
<cfform name="formName" action="edit.cfm" method="post">
....some additional codes.....
<cfloop query="qryName">
Record1_data Edit button
Record2_data Edit button
Record3_data Edit button
Record4_data Edit button
</cfloop>
....some additional codes.....
</cfform>
Unless there's a really good reason I'd really shy away from using cfform there's rarely a good reason to use it
You need to pass in some sort of form variable that has the corresponding ID to what you're pulling into the database.
<form name="formName" action="edit.cfm" method="post">
<cfloop query="qryName">
<input type="checkbox" name="Record" value="#qryName.ID#" /> Record #qryName.ID#
</cfloop>
</form>