I have an HTML file which contains the below code snippet.
<div class="col-sm-2 col-sm-offset-1">
<div class="countBox success" id="success">
<h2>467</h2>
Passed Tests
<span class="glyphicon glyphicon-eye-open"></span>
</div>
</div>
I have a regular expression (.*)</h2>\r\nPassed to get the value 467. It is worked till yesterday. But, it is not working now. I have tried by replacing single slash by double slash to new line and row. Used "\s+" to cover whitespace. All failed in error. Could anyone please guide me on how to get the value as 467 by using regular expression for the above code snippet?
It is better to catch <h2>(\d+)</h2> to ensure only a h2 header with a number inside. By the way, \r\n is only one convention (in windows) to represent end of line, but in unix it is only \n so to be more platform independent, you can do \r?\n (marking the \r as optional) and you have to get on the whitespace in front of Passed., so a good (but not probably the best) regexp would be:
<h2>(\d+)<\/h2>\r?\n\s*Passed
See demo.
Related
I am trying to match a url string and I want to swap when some word is included in this case reviews the problem is that when the url ends on a forward slash my formula adds a double slash. Is there a way to add a slash only when there is no slash at the end?
https://regex101.com/r/cjMEiW/1
Is there a way to add a slash only when there is no slash at the end?
The 'trick' is to use an additional 'dummy' (not used in substitution) group (\/?) which can be empty or contain a slash and not to allow the group 3 to include a slash at its end (.*[^\/$])
See:
https://regex101.com/r/nysBYY/2
Regex:
(<a href='https:\/\/www\.example\.com)\/(reviews)\/(.*[^\/$])(\/?)('>)
Test string:
<a href='https://www.example.com/reviews/citroen/c4/'>here</a>
<a href='https://www.example.com/reviews/citroen/c4'>here</a>
Substitution:
$1/$3/$2/$5
Output:
<a href='https://www.example.com/citroen/c4/reviews/'>here</a>
<a href='https://www.example.com/citroen/c4/reviews/'>here</a>
Check out the answer https://stackoverflow.com/a/72516646/7711283 at Regex, substitute part of a string always at the end for more detailed explanation of the regex of the groups.
P.S. the OPs regex was:
(<a href='https:\/\/www\.example\.com)\/(reviews)\/(.*)('>)
with substitution $1/$3/$2/$4 which resulted in:
<a href='https://www.example.com/citroen/c4//reviews/'>here</a>
<a href='https://www.example.com/citroen/c4/reviews/'>here</a>
I want to split a string based on the lines, meaning seperating contents on seperate lines.
Example -
Hello I
am
Bill Gates
Final Array should be ["Hello I","am","Bill Gates"]
I tried using split function and passing '\n' but it ain't working.
<#assign finalValue = body?split('\n') />
I am not getting the desired result in this case. Can you please help me out with this?
For more details, read below -
I am trying to fetch country from an address. Country is always on the last line of address, so I am trying to SPLIT the address based on lines, thus fetching last line which is the desired output.
Example -
ABC, Industries Ltd.,
XYZ Street,
United States.
So here, I am using split function as address?split("\n") but it ain't working.
So, I tried splitting using Developers Console and it worked fine there. Used split() function.
Upon fetching the address value though, I am getting it as -
ABC, Industries Ltd., \n XYZ Street, \nUnited States.
Hence, thought of splitting using \n but it ain't working!
The usual problem is that there are 3 kind of line-breaks in use: \r\n (Windows and some Web protocols), \n (everything else), and very rarely \r (old Mac). The split that works with all is ?split(r'\R', 'r'). Note that the R is capital in \R. That's a regular expression construct, supported since Java 8.
Likely doesn't help the OP, but might help someone else from the frustration of trying to split on line break for an advanced PDF in NetSuite using Freemarker!
You need to use <br />
${var?split(r"<br />", "r")}
EDIT 2: I've now tested the files in a React app. JavaScript works as expected so the only actual problem seems to be that Jest snapshots inconsistently handle escape characters including in way which aren't valid JS, which could make debugging confusing. Tests still work as they should, only looking at the snapshot could be confusing.
EDIT: My question is not a duplicate of the question regarding when to use single or double quotes. I am wondering why escaping a backslash doesn't seem to work in either JSX or Jest snapshots, yet escaping a quote does.
\\ should become \ yet it appears as \\ in the official Jest example
https://github.com/facebook/jest/blob/master/examples/snapshot/tests/snapshots/link.react.test.js.snap
I'm learning Jest and looking over their example for snapshot testing. On the test entitled it properly escapes quotes, the quotes are escaped correctly, but there are parts where two backslashes are together and they're both rendered in the snapshot.
Is this some unique thing or bug related to Jest snapshots?
Here's the test
it('properly escapes quotes', () => {
const tree = renderer
.create(
<Link>
{"\"Facebook\" \\'is \\ 'awesome'"}
</Link>
)
.toJSON();
expect(tree).toMatchSnapshot();
});
And Here's the snapshot output:
exports[`properly escapes quotes 1`] = `
<a
className="normal"
href="#"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
"Facebook" \\'is \\ 'awesome'
</a>
`;
Why aren't the double backslashes rendered as one backslash? After all isn't that how JavaScript works?
I'd appreciate any help.
I've now tested the files in a React app. JavaScript works as expected so the only actual problem seems to be that Jest snapshots inconsistently handle escape characters including in way which aren't valid JS, which could make debugging confusing.
Tests still work as they should, only looking at the snapshot could be confusing.
I had this problem and when I used double the number of slashes in the snapshot it worked.
e.g. instead of \\, use \\\\.
Maybe when the snapshot is read in, it goes through two levels of reduction in Jest.
i've got a document with 38.000 lines.
I'd like to add a <div class="kalle"> in front of each line which contains the word "Kalle" and a <div class="susi"> in front of each line which contains the word "Susi".
Can you help me how to solve this problem?
Type Ctrl+H, then
Find what: ^(.*)(Kalle|Susi)
Replace with: <div class="$2">$1
or
Replace with: <div class="$2">$1$2 if you want to keep kalle and susi in the string
Regular Expression must be checked but NOT dot matches newline
I'm still fairly new to Freemarker and am currently trying to output a bulleted list using the Split builtin.
My code so far is so:
<#list listingname?split(", ") as x>
• ${x} <br />
</#list>
My issue arises when a value from the 'listingname' field contains a comma-space (, ) - this causes the the outputed code to break prematurely.
So for example, let's say:
listingname = "john's company", "bill, bob's tackle and bait", "john do - attorney at law"
The above code would render it as so:
• "john's company"
• "bill
• bob's tackle and bait"
• "john do - attorney at law"
The issue here is that the 2nd set of double-quoted text breaks instead of displaying "bill, bob's tackle and bait" on one line.
So I guess my question is, is there a way to prevent this from happening?
Can't you just pass that listing to FreeMarker as a Java List or array? I mean, it's like you try to parse the list literals of some language here. That's not something you usually do in templates. And ?split is just for spliting, it's certainly not smart enough for this.
But if you indeed has to do this, parsing in the template, what syntactical rules does this listing string follow? Like, what if a list item value contains a quotation mark? Will it be escaped like \"? If the syntax is compatible with FTL's own syntax, you could do <#list ('[' + listingname + ']')?eval as x>.