regular expression to get only letters between a look behind and look ahead - regex

I am trying to extract only the letters from "130b2c94-22ba-4584-b18a-899eb4be045d"
<input type="hidden" name="logonInfo.forceAuthn" value="false" id="sSignOnauthenticateUser_logonInfo_forceAuthn"/>
<input type="hidden" name="logonInfo.inResponseTO" value="_130b2c94-22ba-4584-b18a-899eb4be045d" id="sSignOnauthenticateUser_logonInfo_inResponseTO"/>
<input type="hidden" name="logonInfo.issuerUrl"
I have tried
(?<=name="logonInfo.inResponseTO" value="_).*(?=" id="sSignOnauthenticateUser)
to extracts the string I need, but I need to break it down further to only the letters

Use a DOM Parser. This will reliably interpret the HTML and give you a DOM.
Then use a CSS selector query to find the input elements that have a value attribute which has a value that starts with underscore.
Finally remove all non-letters in that found value using a regex:
const html = `
<input type="hidden" name="logonInfo.forceAuthn" value="false" id="sSignOnauthenticateUser_logonInfo_forceAuthn"/>
<input type="hidden" name="logonInfo.inResponseTO" value="_130b2c94-22ba-4584-b18a-899eb4be045d" id="sSignOnauthenticateUser_logonInfo_inResponseTO"/>
<input type="hidden" name="logonInfo.issuerUrl" >`;
const doc = new DOMParser().parseFromString(html, "text/html");
for (const input of doc.querySelectorAll("input[value^=_]")) {
const letters = input.value.replace(/[^a-z]/gi, "");
console.log(input.name, ":", letters);
}

Related

copy id="uniqueid" as name="uniqueid" with find/replace & regex in notepad++

I have a HTML form which currently has unique id's for each input (or select) like so.
example 1
<input type="number" id="qty-a-row" min="0" max="999" autocomplete="off" value="" style="border:0px; outline:0px; display:inline-block; width:50px;" />
example 2
<select id="ps_a_row" autocomplete="off" style="width:324px; border:0px; outline:0px; display:inline-block">
each id is unique. I'm now trying to add in a name="" with the same value as every id="" found so example 1 above becomes.
<input type="number" id="qty-a-row" name="qty-a-row" min="0" max="999" autocomplete="off" value="" style="border:0px; outline:0px; display:inline-block; width:50px;" />
and example 2 becomes...
<select id="ps_a_row" name="ps_a_row" autocomplete="off" style="width:324px; border:0px; outline:0px; display:inline-block">
and so on for every id="anything" it finds.
I'm using notepad++ and with regex ticked currently trying...
Find = id="(.*)"
Replace = id="\1" name="\1"
but this is only finding some id's and duplicates all other tags it finds after the id it finds too.
The complete code for the form I'm trying to edit is here...
https://pastebin.com/ZAE4Gffk
Find id="([^"]+)" and replace it with id="\1" name="\1" , but you shouldnt use regex for HTML manipulation. Use appropriate tools for that.
Demo

html pattern attribute

I'm trying to limit my text input to only allow letters, not numbers. With a maximum of 100 characters. I'm having trouble finding out how to use the pattern attribute to only allow letters. Here is a portion of my code attempting this.
<form action="http://www.severien.com/grit/formecho.php" method="post" target="_blank">
<label for="videorequests"> Video Requests:</label>
<input type="text" id="videorequests" name="videorequests" maxlength="100" pattern="[a-z]{1,100}" />
<input type="submit" value="Submit" class="submitbutton" />
</form>
Using the attribute maxlength I'm limiting the character input to 100. How do I use pattern to limit the character use to only letters, excluding numerical characters?
use this
pattern="[A-Z a-z]{1,100}"

Angular2 pattern validator on Input

I'm trying to setup a pattern validator with the following regex :
^(((0|[1-9]\d{0,2})(\.\d{2})?)|())$
Try Regex here
That should allow me to get 1 to 3 digits, and then a decimal part of maximum 2 digits, and that should allow empty values as well.
The problem is that either my input is of type text and the validator is rejecting my input (any input since it's not considered as a digit I believe); or the input is of type number and without step="any" my input value is rejected if I have a decimal input (while the regex seems to be working on simpler values), and with step="any" it seems my regex is not working at all, allowing whatever value because of the step.
<form (ngSubmit)="onSubmit()" #bottleUpdatePriceForm="ngForm" >
<div class="form-group" *ngFor="let bottle of bottleArrayToUpdate; let i = index">
<label for="bottlePrice">{{bottle.name}} : </label>
<input type="number" class="form-control" name="bottlePrice" autocomplete="off" step="any"
[pattern]="pricePattern"
[(ngModel)]="bottleArrayToUpdate[i].price">
</div>
<button type="submit" class="btn btn-default">Submit</button>
<!--(click)="bottleUpdatePriceForm.reset();"-->
</form>
EDIT : adding my component code for regex binding
private pricePattern = /^(((0|[1-9]\d{0,2})(\.\d{2})?)|())$/;
Be it text or number I don't really care, I just need the pattern to work on my input... Any insight or something I am missing ?
Here is a working example in a plunkr : https://plnkr.co/edit/znVaS7?p=info
You can switch the input line in the plunkr to see the different cases :
<input type="text" class="form-control" name="bottlePrice" autocomplete="off"
<input type="number" class="form-control" name="bottlePrice" autocomplete="off" step="any"
Unrelated to the main issue : Is there any way to call the form reset from the component rather than directly in the template ?
==> bottleUpdatePriceForm.reset();
I was wondering, this is just for bonus.
Thanks a lot
This is not a direct solution for the not working regex, but this works with the same purpose. So remove the pattern and just change your input with max and min instead:
<input type="number" class="form-control" name="bottlePrice"
autocomplete="off" step="any" max="999" min="0"
[(ngModel)]="bottleArrayToUpdate[i].price">

Keep part of matched string when replacing with RegEx in Sublime

I have about 1,000 lines of html that look like this:
<input type="text" readonly value="some-value-here" class="unit size1of2" />
I am able to find all of those lines using the RegEx search of
<input type="text" readonly value="[^<]+" class="unit size1of2" />
However, I am trying to change all of them to
<input type="hidden" value="same-value-that-was-found" />
Any ideas on what I need to do to accomplish this?

Spaces in string in <input type="text"> django templates

I have this code in a Django Template:
input type="text" name="ppoisNomePOI" value={{ request.session.ppoisNomePOI }}
If my "request.session.ppoisNomePOI" is "John" then in the page it appears "John" in the input, but if my "request.session.ppoisNomePOI" is "John Flanders Simpson" it only appears "John"
I assume it was a problem with the spaces in the value.
From the sounds of it, the browser is probably treating the subsequent words as empty attributes and being interpreted as:
<input type="text" name="ppoisNomePOI" value="John" Flanders Simpson>
Try putting quotes around the value.
value="{{ request.session.ppoisNomePOI }}"
This will force it to be interpreted as:
<input type="text" name="ppoisNomePOI" value="John Flanders Simpson">