How to define stash issue regex to match only from begining? - regex

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+)\"

Related

regex extract username from 2 types of url

I'm currently using this regex (?<=\/movie\/)[^\/]+, but it only matches the username from the second url, i know i could make a if (contains /movie/): use this regex, else: use another regex on my code, but i'm trying to do this directly on regex.
http://example.com:80/username/token/30000
http://example.com:80/movie/username/token/30000.mp4
To complete the Tensibai's answer, if you have not a port in url, you can use the last dot in url to start your regex :
\.[^\/\.]+\/(?:movie\/)?([^\/]+)
(demo)
You can use something like this to make the movie/ optional and have the username in a named capture group (Live exemple):
\d[/](?:movie\/)?(?<username>[^/]+)[/]
using \d/ to anchor the start of match at after the url.

RegEX Trying to trigger optional search

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

Match part of url with regex

I have a challenge with a regex match to a url I hope I can bug some of you clever heads with :-)
Please take a look at this testcase https://www.regex101.com/r/bH4hE1/2
I use the regex: (\w+)(.\w+)+(?!.*(\w+)(.\w+)+)
Problem is, it only finds reports.html but I also need to find reports in the first url
https://my.website.com/reports?ref_=kdp_BS
https://my.website.com/reports.html
To capture "reports" or "reports.html" in any path, begin your match after the last /, and capture word characters and .:
/.*\/([.\w+]+)/
See: https://www.regex101.com/r/iZ7dF3/8
Try:
/([^\/?]+)(?:\?.+)?$/gim
It will work end selects:
reports
reports.html

Regex to parse certain fields of a log file

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

Match string1 but discard if match string2

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.