regex findText with exception - regex-negation

I have a jenkins pipeline in which I've always been searching for a string in case I need to update my build to failure.
findText regexp: 'ERROR', alsoCheckConsoleOutput: true, unstableIfFound: true
https://www.jenkins.io/doc/pipeline/steps/text-finder/
I now need for example to make an exception to allow certain cases of ERROR to be handled differently.
I was looking at this question Regular expression to match a line that doesn't contain a word and this question Regex with exception of particular words but I still could not make it work.
I really suck at regex and trying to play with the different websites I'm struggling a bit with the negatives lookup parts.
Basically I want to ensure that
This is an ERROR bla bla bla
Is an error caught by my regex
But I need to have this as not an error because XYZ shows up before
This XYZ is not an ERROR bla bla bla because of the prefix
I was trying something like this but not really close.
(ERROR)+?:(XYZ)
Basically ERROR can appear more than once in my output lines but XYZ should never be found. If it helps XYZ will always show up before the ERROR
Any idea?

Related

Are negative lookbehinds supported in Impala?

I am using regexp_like in Impala with a negative lookbehind to find a pattern in a string array. I've built the expression as follows against a sample data set.
Running it yields the following error message.
Invalid regex expression: '(?<=Hello).+'
regexp_like(string_field,'(?<!Hello).+')
result
string_field
no match
Hello World, Bye World
match
Cool, Not Cool
no match
Cool, Hello, Bye Bye
This negative lookbehind works in python. Has anyone else come across this? I've tried looking at the documentation but didn't find anything particularly useful.
A better example.
I am trying to find at least one occurrence from a comma separated string array in which at least one of the array elements is not preceded by the keyword e.g. - ('Hello'). A negative lookaround seems like one of the most elegant solutions for the task at hand.
A little clunky, but this works:
regexp_like(string_field, '(^|,)([^H]|H[^e]|He[^l]|Hel[^l]|Hell[^o])')
See live demo.

Match beginning of string with lookbehind and named group

help needed to match full message in a Lookbehind.
Lets say i have the following simplified string:
1 hostname Here is some Text
at the beginning i could have 1 or 2 digits followed by space, which i would ignore.
then i need the first word captured as "host"
and then i would like to look behind to the first space, so that capture group "message" has everything starting after the first 2 digits and space. i.e. "hostname Here is some Text"
my regex is:
^[1-9]\d{0,2}\s(?<host>[\w][\w\d\.#-]*)\s(?<message>(?<=\s).*$)
this gives me:
host = "hostname"
message = "Here is some Text"
I can't figure out how my lookbehind needs to look like.
Thanks for your help.
ok, i found it. What needs to be done is to put message as the first group, and everything else, including the other groups inside the message group:
^[1-9]\d{0,2}\s(?<message>(?<host>[\w][\w\d\.#-]*)\s.*$)

Why does the golang testing package replace spaces with underscores when reporting test failures?

When I run this test and it fails:
func TestCaseA(t *testing.T){
t.Run("my name with spaces", func (t *testing.T){
t.Error("some error message")
})
}
then the name of the test is modified (spaces are changed to underscores) in the output:
--- FAIL: TestCaseA (0.00s)
--- FAIL: TestCaseA/my_name_with_spaces (0.00s)
main.go:10: some error message
FAIL
Why does it do this?
Here's a working example: https://play.golang.org/p/viZjC60Dazg
It's explained in this blog post: https://blog.golang.org/subtests
The full name of a subtest or sub-benchmark is a slash-separated list of its name and the names of all of its parents, starting with the top-level. The name is the corresponding function name for top-level tests and benchmarks, and the first argument to Run otherwise. To avoid display and parsing issues, a name is sanitized by replacing spaces with underscores and escaping non-printable characters. The same sanitizing is applied to the regular expressions passed to the -run or -bench flags.
Some examples could be to make it simpler for automated tools to process the test output, to avoid issues with the shell making regex arguments containing spaces appearing as multiple arguments etc. I'd rather avoid using spaces than deal with this magic renaming.
I found the most definitive answer I could, in the code itself, of course. The rewrite function comment reads
rewrite rewrites a subname to having only printable characters and no white space.
https://golang.org/src/testing/match.go#L133
As to why? I'm guessing JimB hit the nail on the head with his comment:
As for why, maybe because it's easier to reference names without spaces in the cli?
White spaces are bad for cli.

T-SQL Contains not working for values with point as 2nd or 3rd symbol

There is a SQL statement, generated by stored procedure, looking like this:
SELECT Id, Name
FROM UInstitutions as UI
WHERE Contains(UI.Name, #ParamName)
It seems that if value has dot (.) as second or third symbol, it's unsearchable, when searching by exact match or substring. E.g.:
[dbo].[FindRecords] N'b.la bla'
or
[dbo].[FindRecords] N'bl.a bla'
return nothing, while
[dbo].[FindRecords] N'bla. bla'
returns
Id Name
--------------
1388 b.la bla
1389 bl.a bla
1386 bla bla
1390 bla. bla
What could be the reason for this, and how to fix it?
Per MSDN for the Contains statement:
Punctuation is ignored. Therefore, CONTAINS(testing, "computer failure") matches a row with the value, "Where is my computer? Failure to find it would be expensive." For more information on word-breaker behavior, see Configure and Manage Word Breakers and Stemmers for Search.
CONTAINS (Transact-SQL)
Also see: Configure and Manage Word Breakers and Stemmers for Search

How should a string be matched with a regular expression in Objective C

I'm finding it hard to match strings using NSRegularExpression. Generic alpha characters are not a problem with [a-z] but if I need to match a word like 'import' I'm struggling to make it work. I'm sure I have to escape the word in some manner but I can't find any docs around this. A really basic example would be
{{import "hello"}}
where I want to get hold of the string: hello
edit: to clarify - 'hello' could be any string - it's the bit I want returned
This regular expression matches the text between the "-s in your example:
\{\{import "([^"]+)"\}\}
The match will be stored in the first match group.