I need to get an expression to get users in cisco which has not lower privileges 0 or 1.
Users can be found in configuration file in the following way:
username myuser privilege 15 password 7 5345345345
So, I´m trying with expression:
(username.*privilege )(?!([01]))( password 7)
To get all lines with "username privilege" for any user name, followed by a group of characters that aren´t 0 or 1, and followed by "password" and other characters.
But testing in some online tester webpage i am not receiving the desired result.
what am i doing wrong?
Thanks a lot
You can add a word boundary after [01]\b and when that assertion is true, you could still have to match the digits using [0-9]+
The pattern matches password 7 literally, but you could also use [0-9]+ here to match the digits.
.*\b(username.*privilege) (?![01]\b)[0-9]+ (password [0-9]+).*
Regex demo
Note that if you only want to match the whole line, you can omit the capture groups:
.*\busername.*?privilege (?![01]\b)[0-9]+ password [0-9].*
Related
I am new in Angular 4 and was developing sample application where I have user email id and password field.
In password field I have to check String must not contain more than 2 repeated characters and for that, I have made the following regex:
^(?:(.)(?!\1{2,}))*$
But this regex fails.
I also tried with the following regex:
^((.)(?!\2\2))*$
But it angular cli shows error:
Module parse error: Octal literal in strict mode
Can anyone help me in suitable regex for the above?
A slight variation of your first regex works:
^(?:(.)(?!\1\1))+$
See live demo.
You only need to check that there aren't two repeats, since that is true for all cases of "more than 1".
In English, the regex says "composed entirely of characters that aren't followed by 2 copies of themselves".
I need to grab the value of password from db connection string using regex.
This is my current regex .*;(?i)Password=([^;]*).
This works only if there is not any ; character in password.
add key="myKey" value="Data Source=MyDataSource;Initial Catalog=MyDB;User ID=test-user;Password=pA&-pass; unicode=True"
But it fails if there is ; character in password
add key="myKey" value="Data Source=MyDataSource;Initial Catalog=MyDB;User ID=test-user;Password=pass>; unicode=True"
Brief
There will always be ways for your code to break since someone can create a password such as ;Password= such that your string is actually ;Password=;Password=;.
Assuming that is not possible (and also assuming it's not possible for someone to use similar variations such as portions of the password being in the following format ;s= where s is any word or space character), this should work for you.
Code
See regex in use here
(?<=;Password=)(?:(?!;[\w ]+=).)*
Results
Input
add key="myKey" value="Data Source=MyDataSource;Initial Catalog=MyDB;User ID=test-user;Password=pA&-pass; unicode=True"
add key="myKey" value="Data Source=MyDataSource;Initial Catalog=MyDB;User ID=test-user;Password=pass>; unicode=True"
Output
pA&-pass
pass>
Explanation
(?<=;Password=) Positive lookbehind ensuring what precedes matches ;Password literally
(?:(?!;[\w ]+=).)* Tempered greedy token matching any character, but ensuring it doesn't match ;, followed by any word or space characters, followed by =
I try to match the username of users on YouNow from a specific field.
I extracted this html, I try to extract the username _You Won
"\n\t\t\t\t\t\t14\n\t\t\t\t\t\t_You Won\n\t\t\t\t\t"
This is my regex attempt:
(\d+)[\\n\\t]+([\W\w]+[^\\n\\t"$])
This worked fine, first I match a number which is the level, then I match the username. However, if the username ends with either t or n then it does not get the last letter. So user game 1n would get cut down to game 1
Does someone know how I can fetch the username correctly?
Play it:
https://regex101.com/r/j8rufa/2
You could use Positive Lookahead at the end instead of [^\\n\\t"$].
Your code will be:
(\d+)[\\nt]+([\W\w]+(?=\\n\\t))
Demo: https://regex101.com/r/j8rufa/4
You can also use Positive Lookbehind to further enhance the code to ensure that the whole name is matched. For example, if the name is something like t_You Won, it will be matched without any issues:
(\d+)[\\nt]+(?<=\\t)([\W\w]+(?=\\n\\t))
Demo: https://regex101.com/r/j8rufa/6
I have this log line:
blabla#gmail.com, Portal, qtp724408050-38, com.blabla.search.lib.SearchServiceImpl .logRequest, [Input request is lookupRequestDTO]
I need to find a regex that grabs that email, then matches lookupRequestDTO ignoring everything in between.
Currently my regex grabs the whole line:
([\w-\.]+)#gmail.com,(.+)lookupRequestDTO
How do I not match anything in between the email and lookupRequestDTO ?
What about this?
([^,]+).*?lookupRequestDTO
[^,]+ matches everything up until the first comma so it should get you the email
It assumes lookupRequestDTO is a criteria for your search. If it is a variable you want to retrieve, you could use this :
([^,]+).*?\[Input request is ([^\]]+)
Assuming you're using PCRE (php, perl, etc., and this should work in javascript):
([\w-\.]+?#gmail\.com),(?:.+)(lookupRequestDTO)
Out of capture groups 1 and 2, you'll get:
MATCH 1
blabla#gmail.com
lookupRequestDTO
Working example: http://regex101.com/r/yW9eU3
World's most convuluted title I know, an example should explain it better. I have a large txt file in the below format, though details and amount of lines will change everytime:
Username: john_joe Owner: John Joe
Account:
CLI:
Default:
LGICMD:
Flags:
Primary days:
Secondary days:
No access restrictions
Expiration:
Pwdlifetime:
Last Login:
Maxjobs:
Maxacctjobs:
Maxdetach:
Prclm:
Prio:
Queprio:
CPU:
Authorized Privileges:
BYPASS
Default Privileges:
SYSPRV
This sequence is repeated a couple of thousand times for different users. I need to find every user (ideally the entire first line of the above) that has SYSPRV under "Default Permissions".
I know I could write an application to do this, I was just hoping their might be a nice regex I could use.
Cheers
^Username:\s*(\S+)((?!^Username).)*Default Privileges:\s+SYSPRV
with the option to make ^ match start of line, and to make dot match newlines, will isolate those records and capture the username in backreference no. 1. Tell me which language you're using, and I'll provide a code sample.
Explanation:
^Username:\s: match "Username" at the start of the line, a colon and any whitespace.
(\S)+": match any non-whitespace characters and capture them into backreference no. 1. This will be the Username.
((?!Username).)*: Match any character as long as it's not the "U" of "Username". This ensures that we won't accidentally cross over into the next record.
Default Privileges:\s+SYSPRV: match the required text.
So in Python, for example, you would use:
result = re.findall(r"(?sm)^Username:\s*(\S+)((?!^Username).)*Default Privileges:\s+SYSPRV", subject)