Extract string using Powershell between two points of reference - powershell

I am trying to extract a string of data from text file that I downloaded using EWS. I am using powershell to do this. A snippet of the file is as follows.
<table class="button" style="border-collapse: collapse; border-spacing: 0; overflow:
hidden; padding: 0; text-align: left; vertical-align: top; width: 100%;"><tbody>
<tr style="padding: 0; text-align: left; vertical-align: top;"><td style="-moz-hyphens: none;
-webkit-hyphens: none; -webkit-text-size-adjust: none; background: #049FD9;
border: none; border-collapse: collapse !important; border-radius: 2px; color: #fff; display: block; font-family: 'Helvetica-Light','Arial',sans-serif; font-size: 14px; font-weight: lighter; hyphens: none; line-height:19px; margin: 0; padding: 8px 16px; text-align: center; vertical-align: top; width: auto
!important; word-break: keep-all;">
<a href="https://www.website.com:443/idb/setPassword?t=BcHJEoIgAADQD%2BKQjqZ4VEKtBHLJJm82uWDuxCR%2Bfe%2B58Rl9HRz6QddWkO5MLDXuF6e9m%2Bo0z%2FCVS%2B9IenAp5m5yTfYRa%2BAn4jdWHHF7HTyqRZiRRiNDEE%2BK7ZJywLKeNCTj4ewu4QNu02qXB0ZTXTyxXADwaLeluZGVPCxGXunpVcHbiCVAWRR7ykqGensLVBsqNUpl%2FQE%3D"
style="-webkit-text-size-adjust: none; font-weight: 100; color: #fff; font-family: 'Helvetica-Light','Arial',sans-serif; font-size: 20px; font-weight: lighter; line-height: 32px; text-decoration: none;">Get Started</a> </td></tr></tbody></table></td>
I want to extract this part BcHJEoIgAADQD%2BKQjqZ4VEKtBHLJJm82uWDuxCR%2Bfe%2B58Rl9HRz6QddWkO5MLDXuF6e9m%2Bo0z%2FCVS%2B9IenAp5m5yTfYRa%2BAn4jdWHHF7HTyqRZiRRiNDEE%2BK7ZJywLKeNCTj4ewu4QNu02qXB0ZTXTyxXADwaLeluZGVPCxGXunpVcHbiCVAWRR7ykqGensLVBsqNUpl%2FQE%3D
I've tried -matches and using regex lookbehinds and forwards but nothing seems to be able to grab that part only.
Thought something like this might work
$a = Get-Content $path
$a -match '(?<=setPassword\?t\=)(.+)(?=" style)'
$matches
But it comes up blank

Best not to use string manipulation for this; use existing libraries and classes.
So first of all, treat your URI as a [uri]:
$uri = [System.Uri]'https://www.website.com/idb/setPassword?t=BcHJEoIgAADQD%2BKQjqZ4VEKtBHLJJm82uWDuxCR%2Bfe%2B58Rl9HRz6QddWkO5MLDXuF6e9m%2Bo0z%2FCVS%2B9IenAp5m5yTfYRa%2BAn4jdWHHF7HTyqRZiRRiNDEE%2BK7ZJywLKeNCTj4ewu4QNu02qXB0ZTXTyxXADwaLeluZGVPCxGXunpVcHbiCVAWRR7ykqGensLVBsqNUpl%2FQE%3D'
Now you can get the query string like this:
$query = $uri.Query
That will start with ?t=, so let's parse it:
$queryData = [System.Web.HttpUtility]::ParseQueryString($query)
The resulting object has a set of keys, one for each value. Since the key you want is called t, you can get the value like this:
$queryData['t']

So I figured out the text document I was outputting to was word wrapping part of the long URL. I ended up outputting with the -Width command so it wouldn't do that.
$email | Out-File $path -Width 9999999
Then I ended up using matches to grab the string I needed using.
$a = Get-Content $path | Where-Object {$_ -match '(?<=https:\/\/www\.website\.com:443\/idb\/setPassword\?t=)(.+)(?=" style)'}
$matches[1]
Hope that helps someone.

Related

Unwanted line breaks added wrongly in outlook

I am sending emails through a java program using velocity template.
When I open my email in Papercut, the render is looking good but when I open the same email with Outlook, I have a lot of unwanted line breaks.
I have modified the CSS in many ways like adding a specific width for table tag etc, I can see my modifications applied in Papercut but nothing in Outlook in terms of width.
PapercutRender1
OutlookRender1
Here the Html template:
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>My text </title>
<style>
/* -------------------------------------
GLOBAL RESETS
------------------------------------- */
img {
border: none;
-ms-interpolation-mode: bicubic;
max-width: 100%;
}
body {
background-color: #f6f6f6;
font-family: sans-serif;
-webkit-font-smoothing: antialiased;
font-size: 14px;
line-height: 1.4;
margin: 0;
padding: 0;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
table {
border-collapse: separate;
mso-table-lspace: 0pt;
mso-table-rspace: 0pt;
width: 100%;
}
table td {
font-family: sans-serif;
font-size: 14px;
vertical-align: top;
}
/* -------------------------------------
BODY & CONTAINER
------------------------------------- */
.body {
background-color: #f6f6f6;
width: 100%;
}
/* Set a max-width, and make it display as block so it will automatically stretch to that width, but will also shrink down on a phone or something */
.container {
display: block;
Margin: 0 auto !important;
/* makes it centered */
max-width: 580px;
padding: 10px;
width: auto !important;
width: 580px;
}
/* This should also be a block element, so that it will fill 100% of the .container */
.content {
box-sizing: border-box;
display: block;
Margin: 0 auto;
max-width: 580px;
padding: 10px;
}
/* -------------------------------------
HEADER, FOOTER, MAIN
------------------------------------- */
.main {
background: #fff;
border-radius: 3px;
width: 100%;
}
.wrapper {
box-sizing: border-box;
padding: 20px;
}
.footer {
clear: both;
padding-top: 10px;
text-align: center;
width: 100%;
}
.footer td,
.footer p,
.footer span,
.footer a {
color: #999999;
font-size: 12px;
text-align: center;
}
/* -------------------------------------
TYPOGRAPHY
------------------------------------- */
h1,
h2,
h3,
h4 {
color: #000000;
font-family: sans-serif;
font-weight: 400;
line-height: 1.4;
margin: 0;
Margin-bottom: 30px;
}
h1 {
font-size: 35px;
font-weight: 300;
text-align: center;
text-transform: capitalize;
}
p,
ul,
ol {
font-family: sans-serif;
font-size: 14px;
font-weight: normal;
margin: 0;
Margin-bottom: 15px;
}
p li,
ul li,
ol li {
list-style-position: inside;
margin-left: 5px;
}
a {
color: #3498db;
text-decoration: underline;
}
/* -------------------------------------
BUTTONS
------------------------------------- */
.btn {
box-sizing: border-box;
width: 100%;
}
.btn > tbody > tr > td {
padding-bottom: 15px;
}
.btn table {
width: auto;
}
.btn table td {
background-color: #ffffff;
border-radius: 5px;
text-align: center;
}
.btn a {
background-color: #ffffff;
border: solid 1px #3498db;
border-radius: 5px;
box-sizing: border-box;
color: #3498db;
cursor: pointer;
display: inline-block;
font-size: 14px;
font-weight: bold;
margin: 0;
padding: 12px 25px;
text-decoration: none;
text-transform: capitalize;
}
.btn-primary table td {
background-color: #3498db;
}
.btn-primary a {
background-color: #3498db;
border-color: #3498db;
color: #ffffff;
}
/* -------------------------------------
OTHER STYLES THAT MIGHT BE USEFUL
------------------------------------- */
.last {
margin-bottom: 0;
}
.first {
margin-top: 0;
}
.align-center {
text-align: center;
}
.align-right {
text-align: right;
}
.align-left {
text-align: left;
}
.clear {
clear: both;
}
.mt0 {
margin-top: 0;
}
.mb0 {
margin-bottom: 0;
}
.preheader {
color: transparent;
display: none;
height: 0;
max-height: 0;
max-width: 0;
opacity: 0;
overflow: hidden;
mso-hide: all;
visibility: hidden;
width: 0;
}
.powered-by a {
text-decoration: none;
}
hr {
border: 0;
border-bottom: 1px solid #f6f6f6;
Margin: 20px 0;
}
/* -------------------------------------
RESPONSIVE AND MOBILE FRIENDLY STYLES
------------------------------------- */
#media only screen and (max-width: 620px) {
table[class=body] h1 {
font-size: 28px !important;
margin-bottom: 10px !important;
}
table[class=body] p,
table[class=body] ul,
table[class=body] ol,
table[class=body] td,
table[class=body] span,
table[class=body] a {
font-size: 16px !important;
}
table[class=body] .wrapper,
table[class=body] .article {
padding: 10px !important;
}
table[class=body] .content {
padding: 0 !important;
}
table[class=body] .container {
padding: 0 !important;
width: 100% !important;
}
table[class=body] .main {
border-left-width: 0 !important;
border-radius: 0 !important;
border-right-width: 0 !important;
}
table[class=body] .btn table {
width: 100% !important;
}
table[class=body] .btn a {
width: 100% !important;
}
table[class=body] .img-responsive {
height: auto !important;
max-width: 100% !important;
width: auto !important;
}
}
/* -------------------------------------
PRESERVE THESE STYLES IN THE HEAD
------------------------------------- */
#media all {
.ExternalClass {
width: 100%;
}
.ExternalClass,
.ExternalClass p,
.ExternalClass span,
.ExternalClass font,
.ExternalClass td,
.ExternalClass div {
line-height: 100%;
}
.apple-link a {
color: inherit !important;
font-family: inherit !important;
font-size: inherit !important;
font-weight: inherit !important;
line-height: inherit !important;
text-decoration: none !important;
}
.btn-primary table td:hover {
background-color: #34495e !important;
}
.btn-primary a:hover {
background-color: #34495e !important;
border-color: #34495e !important;
}
}
</style>
</head>
<body class="">
<table style="width:560px;" border="0" cellpadding="0" cellspacing="0" class="body">
<tr>
<td> </td>
<td class="container">
<div class="content">
<!-- START CENTERED WHITE CONTAINER -->
<table style="width:560px;" class="main">
<!-- START MAIN CONTENT AREA -->
<tr>
<td class="wrapper">
<table style="width:560px;" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<!--<img src="http://localhost:8080/wmm-admin/icons/spidex-wmm_original.png" style="width:65%" /> -->
<br/>
<br/>
<p><b>Webb, however, is 100 times more powerful than astronomy's godfather of space telescopes and can peer much deeper into space.
Hubble studies the universe predominantly at ultraviolet and optical, or visible, wavelengths, which is the same type of light we detect with our eyes.
Webb, on the other hand, is set up to specifically look in the infrared, which is invisible to our eyes but allows it to identify the glow from the most distant objects in the universe.
It works in much the same way night vision goggles use thermal imaging technology to capture infrared light.
Because the universe is expanding, just about all of the galaxies that we see from Earth are moving away from us. This means that to us, their light appears to have a longer wavelength, or a redshift.
For very distant objects, this red shift is so large that they can only be observed in the infrared spectrum, which is where Webb comes in, while Hubble focuses on ultraviolet light.
For this reason, the two will work in tandem for a while so that scientists can analyse the data provided by both to help advance our knowledge of the cosmos and how humans first came to be.
Webb began development in 1996 and was originally envisaged to launch in 2007, but a major redesign in 2005 put this back and a series of further delays led to it eventually making it to orbit at the end of last year.
THE JAMES WEBB TELESCOPE
The James Webb telescope has been described as a 'time machine' that could help unravel the secrets of our universe.
The telescope will be used to look back to the first galaxies born in the early universe more than 13.5 billion years ago, and observe the sources of stars, exoplanets, and even the moons and planets of our solar system.
Webb, however, is 100 times more powerful than astronomy's godfather of space telescopes and can peer much deeper into space.
Hubble studies the universe predominantly at ultraviolet and optical, or visible, wavelengths, which is the same type of light we detect with our eyes.
Webb, on the other hand, is set up to specifically look in the infrared, which is invisible to our eyes but allows it to identify the glow from the most distant objects in the universe.
It works in much the same way night vision goggles use thermal imaging technology to capture infrared light.
Because the universe is expanding, just about all of the galaxies that we see from Earth are moving away from us. This means that to us, their light appears to have a longer wavelength, or a redshift.
For very distant objects, this red shift is so large that they can only be observed in the infrared spectrum, which is where Webb comes in, while Hubble focuses on ultraviolet light.
For this reason, the two will work in tandem for a while so that scientists can analyse the data provided by both to help advance our knowledge of the cosmos and how humans first came to be.
Webb began development in 1996 and was originally envisaged to launch in 2007, but a major redesign in 2005 put this back and a series of further delays led to it eventually making it to orbit at the end of last year.
THE JAMES WEBB TELESCOPE
The James Webb telescope has been described as a 'time machine' that could help unravel the secrets of our universe.
The telescope will be used to look back to the first galaxies born in the early universe more than 13.5 billion years ago, and observe the sources of stars, exoplanets, and even the moons and planets of our solar system.
End test:</b> <i>The identified trigger result is higher than the set value.</i> </p>
</td>
</tr>
</table>
</td>
</tr>
<!-- END MAIN CONTENT AREA -->
</table>
<!-- START FOOTER -->
<div class="footer">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="content-block"></td>
</tr>
</table>
</div>
<!-- END FOOTER -->
<!-- END CENTERED WHITE CONTAINER -->
</div>
</td>
<td> </td>
</tr>
</table>
</body>
</html>
On the other hand, If I put this text instead, I have no unwanted line break neither in Papercut nor in Outlook:
PapercutRender2
Outlook2
Do you have any idea of how I can get a correct render in Outlook ?
I found out the origin of the problem. I removed the "width: auto !important;" line from the .container class settings:
Before
.container {
display: block;
Margin: 0 auto !important;
/* makes it centered */
max-width: 580px;
padding: 10px;
width: auto !important;
width: 580px;
}
And after correction:
.container {
display: block;
Margin: 0 auto !important;
/* makes it centered */
max-width: 580px;
padding: 10px;
width: 580px;
}
Then it worked.

Move price tag from left to right

can you please give me the right CSS snippet to move these price tags from left to right? I am very insecure with this positioning and don’t want to produce crippled code so it would be great to get some help here.
https://prnt.sc/1x10vpj
I suppose it is thie, but not 100% sure:
position: absolute;
bottom: 12px;
left: 12px;
padding: 3px 11px;
margin: 0;
min-width: 0;
min-height: 0;
line-height: 20px;
border-radius: 50px;
background-color: #fff;
color: #111;
font-weight: 700;
font-size: 13px;
}```
Thanks and regards!
Seems a bit of an incomplete question. Would be good to see where the element s sit in relation to other elelements and also associated CSS.
But looks like it is as simple as changing left, to right in your CSS.

Extract URL from text file then parse using Powershell

I am trying to extract a URL from a text file. I am using PowerShell to do this. The last part of the URL will be different each time. A snippet of the file is as follows:
<table class="button" style="border-collapse: collapse; border-spacing: 0; overflow:
hidden; padding: 0; text-align: left; vertical-align: top; width: 100%;"><tbody>
<tr style="padding: 0; text-align: left; vertical-align: top;"><td style="-moz-hyphens: none;
-webkit-hyphens: none; -webkit-text-size-adjust: none; background: #049FD9;
border: none; border-collapse: collapse !important; border-radius: 2px; color: #fff; display: block; font-family: 'Helvetica-Light','Arial',sans-serif; font-size: 14px; font-weight: lighter; hyphens: none; line-height:19px; margin: 0; padding: 8px 16px; text-align: center; vertical-align: top; width: auto
!important; word-break: keep-all;">
<a href="https://www.website.com:443/idb/setPassword?t=BcHJEoIgAADQD%2BKQjqZ4VEKtBHLJJm82uWDuxCR%2Bfe%2B58Rl9HRz6QddWkO5MLDXuF6e9m%2Bo0z%2FCVS%2B9IenAp5m5yTfYRa%2BAn4jdWHHF7HTyqRZiRRiNDEE%2BK7ZJywLKeNCTj4ewu4QNu02qXB0ZTXTyxXADwaLeluZGVPCxGXunpVcHbiCVAWRR7ykqGensLVBsqNUpl%2FQE%3D"
style="-webkit-text-size-adjust: none; font-weight: 100; color: #fff; font-family: 'Helvetica-Light','Arial',sans-serif; font-size: 20px; font-weight: lighter; line-height: 32px; text-decoration: none;">Get Started</a> </td></tr></tbody></table></td>
I want to extract the URL that starts with:
https://www.website.com:443/idb/setPassword
The string after the t= will be different each time. How can I extract the entire URL into a variable that I can then parse to get the info I need, which is the string of characters after the ?t=?
Try the following:
$content = Get-Content -Path 'C:\test.txt'
[regex]$regex = '(?<=href="https:\/\/www\.website\.com:443\/idb\/setPassword\?t=)(.*)(?=" )'
$regex.Matches($content).Value
In $content replace the path with your text file that contains the URL and update the $regex with the correct URL to the site.
This method use Regex to match before (?<= ) the websites URL and after (?= ), and then selects the text in the middle.
Here is a solution that uses a combination of Select-String with a regular expression to get the URL and the [system.uri] class to interrogate it.
$Text = get-content 'html-sample.txt'
$URLString = ((Select-String '(http[s]?)(:\/\/)([^\s,]+)(?=")' -Input $Text).Matches.Value)
#At this point $URL is a string with just the URL and querystring as requested
$URLString
#Heres how you might interrogate it
[system.uri]$URL = $URLString
$Token = ($URL.Query -split '=')[1]
$URL.host
$Token
Explanation:
Uses the regular expression (http[s]?)(:\/\/)([^\s,]+)(?=") with Select-String to extract the URL. Note this will only get the first match by default, use the -AllMatches switch of Select-String if you need to match multiple URLs and then you'll need to deal with each result via a ForEach loop.
Uses [system.uri] to cast the URL as a URI object.
Access the host property of the object to return the base URL.
Accesses the query property of the object to return the query string and replaces the '?t=' part of the string using a regex that only does the replace where it appears in the beginning of the string (^ token) and using backslashes to escape the other regex special characters.
here's another way by casting [xml] to read the file as an xmldocument....
$thisxml = [xml](gc .\hypertext.html)
then drill down to the node you want using xpath
$thisxpath = ($thisxml).SelectNodes("//table//tr//td//a").href
then cast [system.uri] to parse and select the uri pieces you want.
$thisuri = [System.Uri]$thisxpath | %{($_.Scheme + "://" + $_.host + $_.LocalPath)}

Bypass ionic 2 component and use default html tag

Let's say I want to create a custom button element that extends the default html button tag.
My component would look more or less like this:
#Component({
selector: 'my-button',
styles: []
template: `<button><ng-content></ng-content></button>`
})
export class MyButton{}
The issue is that instead of a regular HTML button, I get the ionic2 button. How can I bypass the ionic 2 button component and create my own?
Have you tried with an anchor element?
<a class="my-button"><ng-content></ng-content></a>
and some default button styles like these (or the styles you want to apply to it):
a.my-button {
align-items: flex-start;
text-align: center;
cursor: default;
color: buttontext;
border-image-source: initial;
border-image-slice: initial;
border-image-width: initial;
border-image-outset: initial;
border-image-repeat: initial;
background-color: buttonface;
box-sizing: border-box;
padding: 2px 6px 3px;
border-width: 2px;
border-style: outset;
border-color: buttonface;
padding: 1px 6px;
text-rendering: auto;
color: initial;
letter-spacing: normal;
word-spacing: normal;
text-transform: none;
text-indent: 0px;
text-shadow: none;
display: inline-block;
text-align: start;
margin: 0em 0em 0em 0em;
font: 13.3333px Arial;
}

Blockquote not aligning

I'm designing a responsive site which means the layout changes. When viewed as wide as possible, my blockquote wraps to the next line. I would like for it to be on the same line.
I have managed to fix the open quote by adding some text-indent however I'm unable to move the close quote.
My HTML:
<blockquote><p class="blockQuote">In recent years we have noticed a growth in demand for audit services, by enterprises with foreign investment, partly because of the demands on the part of organizations such as the CPI and the central bank.</p></blockquote>
CSS:
blockquote {
font-family: serif;
font-style: italic;
color: #000;
margin: 0px 0px 10px 0px;
}
blockquote:before {
content: "\201C";
}
blockquote:after {
content: "\201D";
blockquote:before {
position: absolute;
width: 60px;
height: 60px;
line-height: 1;
font-size: 120px;
}
blockquote:after {
position: absolute;
width: 60px;
height: 60px;
line-height: 1;
font-size: 120px;
}
When I use a span element, the close quote fixes but the open quote looks like it should move further up.
Add <span> tag instead of <p> tag. Working JSFiddle here https://jsfiddle.net/jfmf4ujc/