1 liner regex to get everything before semi colon - nintex-workflow

I have this variable 1874;#Bob Williams. I tried this and it should give me 1874 but it's giving me the entire variable. Any idea?
(?<=\w+;)

Whatever tool/engine you're using is removing what it matches and returns what remains after removal, so this should work for you: ;.+

A bit off topic but you dont need a regex for this. Not at all. Use Substringinstead:
var s = "1874;#Bob Williams";
s = s.Substring(0, s.IndexOf(';')); // If your input might not contain a semi colon, check the return of IndexOf
// s == "1874"
Demo
If you are writing .NET code as your tag show, use this.

Related

regex look-behind expression incompatibily with IE

I am using this regex expression for an input. When I try it in Chrome, it works well, but not when I try in IE. The regex editor that I am using advice me that the negative look-behind expression could not work for some browsers.
How can I adapt the expression to make it work for IE? I am using it to make impossible to end the input with /.
(^(?!.*\/\/)^(?!^\/)[A-Za-z0-9\/\-?:().,'+\s]+(?<!\/))
Negative look-behind expression not working in IE:
(?<!\/))
Thanks in advance and best regards.
If you don't want a / at the end of the string, you could add another lookahead.
^(?!.*\/\/)^(?!^\/)(?!.*\/$)[A-Za-z0-9\/\-?:().,'+\s]+
Regex demo
But in that case, it might be easier to use a version where the / is not in the character class but optionally repeated preceding the character class.
This way, it can not occur at the start or at the end of the string, and there can also not be //
^[A-Za-z0-9?:().,'+\s-]+(?:\/[A-Za-z0-9?:().,'+\s-]+)*$
Regex demo

regex with OR condition not working in angularjs [duplicate]

I'm creating a javascript regex to match queries in a search engine string. I am having a problem with alternation. I have the following regex:
.*baidu.com.*[/?].*wd{1}=
I want to be able to match strings that have the string 'word' or 'qw' in addition to 'wd', but everything I try is unsuccessful. I thought I would be able to do something like the following:
.*baidu.com.*[/?].*[wd|word|qw]{1}=
but it does not seem to work.
replace [wd|word|qw] with (wd|word|qw) or (?:wd|word|qw).
[] denotes character sets, () denotes logical groupings.
Your expression:
.*baidu.com.*[/?].*[wd|word|qw]{1}=
does need a few changes, including [wd|word|qw] to (wd|word|qw) and getting rid of the redundant {1}, like so:
.*baidu.com.*[/?].*(wd|word|qw)=
But you also need to understand that the first part of your expression (.*baidu.com.*[/?].*) will match baidu.com hello what spelling/handle????????? or hbaidu-com/ or even something like lkas----jhdf lkja$##!3hdsfbaidugcomlaksjhdf.[($?lakshf, because the dot (.) matches any character except newlines... to match a literal dot, you have to escape it with a backslash (like \.)
There are several approaches you could take to match things in a URL, but we could help you more if you tell us what you are trying to do or accomplish - perhaps regex is not the best solution or (EDIT) only part of the best solution?

Need regex to separate the integer from the array to comma separated

I am looking to have a regex for passing a value in the array to comma separated. Here is the regex I used for the fetching the value.
Regex: id="selectedAgency(.+?)" currently using this regex I am able to find the below value which is matching in
id="selectedAgency[1]"
Hence the outcome I receives is as follows:
&selectedAgencies=[14],[12],[10],[9]
However I would like to have the actual output as the below:
&selectedAgencies= 14,12,10,9
To remove [] use different regex:
Regex : id="selectedAgency\[(\d+)
not sure if this JavaScript version works for you but here it is. Hopefully the regex and replace part should help.
let str = "&selectedAgencies=[14],[12],[10],[9]";
let result = str.replace(/\[(\d+)\]/g, "$1"); //&selectedAgencies=14,12,10,9

Regular Expression Generation for AngularJS ng-pattern

I'm using a regex to validate a form input. So basically a user can input "SELECT some_name of select_match".
So far I have the regex: \bSELECT\b \bof select_match\b
The last part is the middle part, which I think should be [a-zA-Z] but I'm not sure how to place it in the middle. I've read multiple pages but can't get it to work.
Also preferably I'd like the regex to ignore spaces between "SELECT" and of "select_match". Meaning that SELECT blabla of select_match and SELECT blabla of select_match would both be validated as correct.
Can anyone tell me how to do this? Thank you.
If I understood you correctly, this should work:
/^SELECT\s+(\w+)\s+of select_match$/
Notes:
This allows any number of spaces between "SELECT" and the match_name; and between the match_name and the "of" (but, at least 1. To change to at least 0, change the \s+ to a \s*)
After that, the rest of the string must be exactly like that (same spaces and words exactly).
The match_name will be in match group 1.
If this doesn't work, show a bit of your code (where you use it) and we can try to find the problem.
Note: If you are using it in ng-pattern lose the "/"s (being the pattern: ^SELECT\s+(\w+)\s+of select_match$).
Note2: If you are using it in a string, remember you might need to escape every "\" (making it a "\", and the result: ^SELECT\\s+(\\w+)\\s+of select_match$

Restricting file types in AngularJS with HTML input type="file"

So my HTML passes a file into AngularJS, and it is named as myFile.
So I use:
console.log($scope.myFile.type);
and it prints out 'application/pdf'.
But when I use this line:
if ($scope.myFile.type == 'application/pdf'){
// some stuff here
}
or
($scope.myFile.type == {'image/jpeg': fileMimeType})
Those will not ever be equal to true. I have no idea how to run this comparison anymore, and would appreciate snippets that would allow me to somehow create this comparison.
Thanks.
I wish i could make comments, but alas i do not have enough points. Did you try console.log( typeof $scope.myFile.type); to make sure it was a string? Also did the output itself have single quotes in it? because if it does have the quotes in it you'll either need to strip those or compare with the quotes in your string.

Resources