Hi I am trying to create a regex to match a username but ignore if match a specific name, STOPPED in this case.
so I want to match all username excpet STOPPED.
2013-03-09 04:38:13,311 radius-acct-pl[23279] INFO: Add 10.2.2.73 to 'By User-Name/alberto'
2013-03-09 04:38:50,963 radius-acct-pl[23279] INFO: Add 10.1.28.38 to 'By User-Name/STOPPED'
so far I have done \bUser-Name\b\/([a-zA-Z0-9\\\._]+)
but this matches STOPPED also
Thanks
You can use lookahead for that:
\bUser-Name\b(?!.*?STOPPED)
Here (?!.*?STOPPED) is negative lookahead. In other words \bUser-Name\b match will succeed only when it is NOT followed by STOPPED.
Try:
(?i)(?<=/)(?!stopped)[a-z]+
Gets the username after the / unless its stopped regardless of case.
Related
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
So I am using this as a string:
Username entry \([a-z]{3,15}
To search this as an example:
[PA]apf_ms.c:7678 Username entry (host/computer.domain.com) is deleted for mobile a4:c4:94:63:1c:7a
[PA]apf_ms.c:7678 Username entry (username#domain.com) is deleted for mobile 94:e9:6a:ad:14:4d
Trying to wrap my head around regex and it's driving me nuts. My search only gets me so far, I am trying to make host/ optional and can't figure out where to insert it.
Username entry \((?:host/)?[a-z]{3,15}
(?: ... ) is a non-capture group
host/ is what you want to match
? after it means optional
You can use ? make anything optional in regex. The regex can be written as
Username entry \((?:host\/)?[a-z]{3,15}
(?:host\/)? Matches one or zero host/. The ?: within the brackets prevent it from capturing, as we don't want to save the host/ for future use.
Regex Demo
The default regex in Stash to match JIRA ID is
JVM_SUPPORT_RECOMMENDED_ARGS="-Dintegration.jira.key.pattern=\"((?<!([a-z]{1,10})-?)[a-z]+-\d+)\""
But it matches regardless where the JIRA ID's location.
I want it only matches from beginning:
JIRA-1 what ever: match!
something JIRA-1 else: not match
How to edit the regex?
Following don't work
\"^((?<!([a-z]{1,10})-?)[a-z]+-\d+)\"
and
\"(^(?<!([a-z]{1,10})-?)[a-z]+-\d+)\"
Solution:
^[a-z]+-\d+ will do.
If you want to match the JIRA-<id> only from the beginning you should try:
\"^JIRA-(\d+)\"
I'm using Aweber's automatic email parsing for Unbounce form submissions and it seems that their default regex is a bit wonky:
They match email with \nemail:\s+(.+?)\n and name with \nname:\s+(.+?)\n
The problem is that because I'm not asking users for their name, their regex automatically grabs the next line, which is ===== FORM DATA =====, so it emails users with "Hi ===== FORM DATA =====!"
Here's what a sample Unbounce email looks like:
page_name:
page_id: 2b78ddde-e7bb-11e1-9fde-12313e00ec56
page_url: http://www1.sample.com
variant: C
email: sample#gmail.com
name:
===== FORM DATA =====
email: ["sample#gmail.com"]
ip_address: 88.253.**.**
--
The Unbounce Team
Toll Free 1-888-515-9161
support#unbounce.com
http://unbounce.com
How do I modify their regex so that it stops at the end of the line if there's no value present?
Change the name regex to the following:
\nname:[ \t]+(.+?)\n
The change here is to replace \s with [ \t], because \s will match newlines.
This will cause the match to fail if a name is not provided, if you would like it to still match but put an empty string into the group, you can use the following:
\nname:[ \t]*(.*?)\n
As noted by Evandro Silva, you can make this regex more efficient by replacing the .+? or .*? with [^\n]+ or [^\n]*, respectively.
Try regex pattern [\n\r]name:[^\S\n\r]*([^\n\r]*)
I was using a regular expression for email formats which I thought was ok but the customer is complaining that the expression is too strict. So they have come back with the following requirement:
The email must contain an "#" symbol and end with either .xx or .xxx ie.(.nl or .com). They are happy with this to pass validation. I have started the expression to see if the string contains an "#" symbol as below
^(?=.*[#])
this seems to work but how do I add the last requirement (must end with .xx or .xxx)?
A regex simply enforcing your two requirements is:
^.+#.+\.[a-zA-Z]{2,3}$
However, there are email validation libraries for most languages that will generally work better than a regex.
I always use this for emails
^([a-zA-Z0-9_\-\.]+)#((\[[0-9]{1,3}" +
#"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
#".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
Try http://www.ultrapico.com/Expresso.htm as well!
It is not possible to validate every E-Mail Adress with RegEx but for your requirements this simple regex works. It is neither complete nor does it in any way check for errors but it exactly meets the specs:
[^#]+#.+\.\w{2,3}$
Explanation:
[^#]+: Match one or more characters that are not #
#: Match the #
.+: Match one or more of any character
\.: Match a .
\w{2,3}: Match 2 or 3 word-characters (a-zA-Z)
$: End of string
Try this :
([\w-\.]+)#((?:[\w]+\.)+)([a-zA-Z]{2,4})\be(\w*)s\b
A good tool to test our regular expression :
http://gskinner.com/RegExr/
You could use
[#].+\.[a-z0-9]{2,3}$
This should work:
^[^#\r\n\s]+[^.#]#[^.#][^#\r\n\s]+\.(\w){2,}$
I tested it against these invalid emails:
#exampleexample#domaincom.com
example#domaincom
exampledomain.com
exampledomain#.com
exampledomain.#com
example.domain#.#com
e.x+a.1m.5e#em.a.i.l.c.o
some-user#internal-email.company.c
some-user#internal-ema#il.company.co
some-user##internal-email.company.co
#test.com
test#asdaf
test#.com
test.#com.co
And these valid emails:
example#domain.com
e.x+a.1m.5e#em.a.i.l.c.om
some-user#internal-email.company.co
edit
This one appears to validate all of the addresses from that wikipedia page, though it probably allows some invalid emails as well. The parenthesis will split it into everything before and after the #:
^([^\r\n]+)#([^\r\n]+\.?\w{2,})$
niceandsimple#example.com
very.common#example.com
a.little.lengthy.but.fine#dept.example.com
disposable.style.email.with+symbol#example.com
other.email-with-dash#example.com
user#[IPv6:2001:db8:1ff::a0b:dbd0]
"much.more unusual"#example.com
"very.unusual.#.unusual.com"#example.com
"very.(),:;<>[]\".VERY.\"very#\\ \"very\".unusual"#strange.example.com
postbox#com
admin#mailserver1
!#$%&'*+-/=?^_`{}|~#example.org
"()<>[]:,;#\\\"!#$%&'*+-/=?^_`{}| ~.a"#example.org
" "#example.org
üñîçøðé#example.com
üñîçøðé#üñîçøðé.com