How to select only inline style in html file using regex? - regex

I tried to select the inline styles in p tag and div tag only. But no need to select td, inline styles
regex style=[\"\w\d\.\:\-\'\s\#\;]+
Input:
<p class="Test"><span style="font-family:Verdana">?</span><span style="font:7.0pt 'Times New Roman'">  </span><span>AAA</span></p>
<table cellspacing="0" cellpadding="0" style="border-collapse:collapse; margin-left:0pt">
<tr>
<td style="border-bottom-color:#808080; border-bottom-style:solid; border-bottom-width:0.5pt; border-top-color:#808080; border-top-style:solid; border-top-width:0.5pt; padding-bottom:2.85pt; padding-top:2.85pt; vertical-align:top; width:81pt">
<p class="Tabelle" style="margin-top:3pt; margin-bottom:3pt"><span style="font-family:Tahoma; font-size:9pt">Detail</span></p>
</td>
output:
style="margin-top:3pt; margin-bottom:3pt in p tag
Note:
I need to select only p tag, div tag tags inline styles.

You can try this:
Find by:
(<(?:p|div)[^<]*)(style="[^"]*")([^>]*>)
replace by:
$1$3
C# Code Sample:
using System;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
string pattern = #"(<(?:p|div)[^<]*)(style=""[^""]*"")([^>]*>)";
string substitution = #"$1$3";
string input = #"<p class=""Test""><span style=""font-family:Verdana"">?</span><span style=""font:7.0pt 'Times New Roman'"">  </span><span>AAA</span></p>
<table cellspacing=""0"" cellpadding=""0"" style=""border-collapse:collapse; margin-left:0pt"">
<tr>
<td style=""border-bottom-color:#808080; border-bottom-style:solid; border-bottom-width:0.5pt; border-top-color:#808080; border-top-style:solid; border-top-width:0.5pt; padding-bottom:2.85pt; padding-top:2.85pt; vertical-align:top; width:81pt"">
<p class=""Tabelle"" style=""margin-top:3pt; margin-bottom:3pt""><span style=""font-family:Tahoma; font-size:9pt"">Detail</span></p>
</td>
";
RegexOptions options = RegexOptions.Multiline;
Regex regex = new Regex(pattern, options);
string result = regex.Replace(input, substitution);
System.Console.WriteLine(result);
}
}
Explanation
You get yoru data in group 1

Related

How to test tr(table row) has onclick and style={{ cursor: "pointer" }} in react testing library

<tbody data-testid="offers-list-tablebody">
{ offers.map((Offer) => (
<tr onClick={this.handleTermsAndConditionsBtnClick} style={{ cursor: "pointer" }} key={index}>
}
I tried in this way
const tableBody = list.find("[data-testid='offers-list-tablebody']");
const tableRow1 = tableBody.childAt(0);
const clickElement1 = (tableRow1.key());
expect(clickElement1.onclick).toBeTruthy();
expect(clickElement1).toHaveStyle("cursor: pointer");
The error is Property "onclick does not exist on type string" and it is hsowing value of index when tested.
How to test this?
it is because you are assigning clickElement1 to tableRow1.key() which returns a string.
Replace clickElement with tableRow1 like below
expect(tableRow1.onclick).toBeTruthy();

Translate selection fields from another model - Template Website Odoo 11

I have a selection type field who is coming another model. But, my traduction file do not take it into account. I am looking to find a other solution for translate values fields this select field.
Any idea ?
EDIT :
Here my template code :
...<table class="table table-hover table_requests" id="order_tableau">
<thead>
<tr>
<th scope="col">Reference</th>
<th scope="col">Type</th>
<th scope="col">Applicant</th>
<th scope="col">Date</th>
<th scope="col">State</th>
</tr>
</thead>
<tbody>
<t t-foreach="requests_grc" t-as="request_grc">
<tr id="result_requests" t-att-onclick="'window.location=\'/web#id='+str(request_grc.id)+'&view_type=form&model=website.application&menu_id=299&action=389\''"
t-att-class="'cursor-pointer'">
<td><t t-esc="request_grc.name"/></td>
<td><t t-esc="request_grc.website_application_template_id.name"/></td>
<td><t t-esc="request_grc.applicant_id.name"/></td>
<td><t t-esc="request_grc.date" t-options="{'widget': 'date'}"/></td>
<td><t t-esc="request_grc.state"/></td>
</tr>
</t>
</tbody>
</table>...
Here my Python code :
requests_grc = http.request.env['website.application'].search([])
Result
I would translate the last element on my table : request_grc.state
EDIT :
#http.route('/web_demarches/', auth='user', website=True)
def indexDemarches(self, **kw):
user = http.request.env.user.name
active_new = False
active_in_progress = False
active_completed_request = False
active_refused_request = False
nb_new_request = 0
nb_in_progress_request = 0
nb_completed_request = 0
nb_refused_request = 0
requests_grc = http.request.env['website.application'].search([])
requests_grc_new = http.request.env['website.application'].search([('state', '=', 'new')])
requests_grc_in_progress = http.request.env['website.application'].search(['|', ('state', '=', 'in_progress'),
('state', '=', 'is_pending')])
requests_grc_completed = http.request.env['website.application'].search([('state', '=', 'completed')])
requests_grc_refused = http.request.env['website.application'].search([('state', '=', 'rejected')])
for request_new in requests_grc_new:
nb_new_request = nb_new_request + 1
for request_in_progress in requests_grc_in_progress:
nb_in_progress_request = nb_in_progress_request + 1
for request_completed in requests_grc_completed:
nb_completed_request = nb_completed_request + 1
for request_refused in requests_grc_refused:
nb_refused_request = nb_refused_request + 1
return http.request.render('grc_parthenay.demarches', {
'user': user,
'active_new': active_new,
'active_in_progress': active_in_progress,
'active_completed_request': active_completed_request,
'active_refused_request': active_refused_request,
'requests_grc': requests_grc,
'requests_grc_new': requests_grc_new,
'requests_grc_in_progress': requests_grc_in_progress,
'requests_grc_completed': requests_grc_completed,
'requests_grc_refused': requests_grc_refused,
'nb_new_request': nb_new_request,
'nb_in_progress_request': nb_in_progress_request,
'nb_completed_request': nb_completed_request,
'nb_refused_request': nb_refused_request,
})

Apache Velocity - if clause

I use Apache Velocity for create an e-mail template.
I have a mail message that contain a table with a list of elements, for create it I had used a #foreach.
In this table I'll add a column contained a conditional string, If the element is empty the string are string1 if is not empty are string2.
This is my code:
#foreach( $item in $list )
<td style="max-width: 140px; word-wrap: break-word;">
#if(${value} not null) 'String1' #else 'String2'#end</td>
#end
Error log:
org.apache.velocity.runtime.parser.ParseException: Encountered "null" at line 25, column 131. Was expecting one of:
"[" ...
"{" ...
"(" ...
<STRING_LITERAL> ...
"true" ...
"false" ...
<INTEGER_LITERAL> ...
<FLOATING_POINT_LITERAL> ...
<IDENTIFIER> ...
"{" ...
"[" ...
at org.apache.velocity.runtime.parser.Parser.generateParseException(Parser.java:3679)
I don't find any help in stack... anyone can help me?
I think this can run in your case:
#if( $value)
<td style="max-width: 140px; word-wrap: break-word;">String1</td>
#else
<td style="max-width: 140px; word-wrap: break-word;">String2</td>
#end
Try to read this question

converting Wildcard to Regex

I'm new in MVC, I want to perform Wildcard (*, ?) search on database. This is what I have done by using Regex:
Controller:
using System.Linq;
using System.Text.RegularExpressions;
using System.Web.Mvc;
using WebApplication1.Models;
namespace WebApplication1.Controllers
{
public class HomeController : Controller
{
CrossWord_dbEntities db = new CrossWord_dbEntities();
public ActionResult Index(string searching)
{
if (searching == null)
{
searching = "*";
}
string regEx = WildcardToRegex(searching);
return View(db.tbl_values.ToList().Where(x => Regex.IsMatch(x.Name, regEx, RegexOptions.Singleline)));
}
public static string WildcardToRegex(string pattern)
{
return "^" + Regex.Escape(pattern).
Replace("\\*", ".*").
Replace("\\?", ".") + "$";
}
}
}
View:
#model IEnumerable<WebApplication1.Models.tbl_values>
<br /><br />
#using (Html.BeginForm("Index", "Home", FormMethod.Get))
{
#Html.TextBox("searching") <input type="submit" value="Search" />
}
<table class="table table-striped">
<thead>
<tr>
<th>Results</th>
</tr>
</thead>
<tbody>
#if (Model.Count() == 0)
{
<tr>
<td colspan="3" style="color:red">
No Result
</td>
</tr>
}
else
{
foreach (var item in Model)
{
<tr>
<td>
#item.Name
</td>
</tr>
}
}
</tbody>
</table>
i have in my database three recordes: Hello, Hero, Shalom
when i type " H* " i get the result: Hello, Hero - this works great
but when i type " *lom " i get "No Result" instead of "Shalom"
or when i type " Hell?" i get "No Result" instead of "Hello"
what i did wrong ?
You can use the following
Expression<Func<tbl_value, bool>> query = m =>
SqlFunctions.PatIndex(searching.ToLower().Replace("*", "%"), m.Name.ToLower()) > 0;
var details = db.tbl_values.Where(query);
Hope this will help you

Search body for a string matched by regexp and replace

I want search a div for a string like "12345" and then put every matched string into a span.
But when find repetitive string, just do it for first matched several time.
Here is a jsfiddle:
function find(){
var regex = new RegExp(/12345/g),
list = $(".test").html().match(regex);
console.log(list)
for(each in list){
replacement = $(".test").html().replace(list[each], "<span class='box'>"+list[each]+"</span>");
$(".test").html(replacement);
}
}
find();
.box{
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="test">
<p>
12345 12345
</p>
</div>
Your approach is faulty: rather than extracting all matching substrings and later iterate them performing single replacements, you may use your own regex inside a String#replace method to modify the substrings "inline", "on-the-match" way:
function find(){
var regex = /12345/g;
var replacement = $(".test").html().replace(regex, "<span class='box'>$&</span>");
$(".test").html(replacement);
}
find();
.box{
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="test">
<p>
12345 12345
</p>
</div>
My solution (fiddle here), with pure JavaScript :
function find(){
var motif = "12345"
var regex = new RegExp(motif, "g")
document.querySelector("div.test").innerHTML = document.querySelector("div.test").innerHTML.replace(regex, "<span class='box'>" + motif + "</span>")
}
find()