Is it possible to use a regex in karate if condition as below
eval if ( xx!=“#regex [0-9]{7}”) karate.log(“success”)
I wanted to execute a if statement, regex evaluation is passed . Above code doesn’t evaluate as regex . It simply prints the log
You can use karate.match():
* def test = '123'
* if (karate.match(test, '#regex [0-9]+').pass) karate.log('pass')
Please refer to the docs: https://github.com/intuit/karate#karate-match
Related
I have below regular expression that check whether we do not have --deploy in a commit message
deploy_review:
<<: *deploy_review_base
except:
refs:
- tags
- master
variables:
- $CI_COMMIT_BRANCH != "review" && $CI_COMMIT_MESSAGE !~ /^.*--deploy/
Now I want to check the opposite of this, that is I want to check where this string --deploy is present in a commit message. Opposite of above expression. is there a way to achieve this ?
Appreciate any help on this
Thanks,
To invert the matching logic, just use =~ instead of !~.
Though your current logic (using !~) checks that the regex pattern does not match. =~ is used to check if the regex pattern does match. You should double check your regex pattern works as expected.
Ok I need this to be working.
As postfix bodycheck go through each line...I need some sort of if else.
If this is subject line and I want to check subject and NOT subject:test.com to be true
(\bSubject:\b)(?!=\bSubject:test.com\b)
This is not working.
Sample line:
Subject:test.com - testing email
If the lookahead is supported, you could write the pattern as:
\bSubject:(?!test\.com\b).*
Regex demo
I am using dataset of github to extract all paths after /api/* and for that I used this below-mentioned query. However, the results are not what I expected it to be. If the regex is wrong can someone please correct it?
Expected results:
/api/v1/user
/api/anything/anything
What actually returns:
Frameworks/TwitterKit.framework/Resources
doc/source/README.rst
*
FROM
`bigquery-public-data.github_repos.files`
WHERE
(REGEXP_CONTAINS(path,r'(s|^.*/api/([^/]*)(?:/.*)?$|$1|)'))
LIMIT
100```
You are using a Perl substitution command in the regex pattern. Look:
s|^.*/api/([^/]*)(?:/.*)?$|$1 |
|| |RHS
||___pattern______________|
|___ action
where RHS (right-hand side) is the replacement.
You only need to use a pattern in BigQuery. To match your desired strings, you may use
^/api/[^/]*(?:/.*)?$
See the RE2 regex demo.
SELECT * FROM `bigquery-public-data.github_repos.files`
WHERE REGEXP_CONTAINS(path,r'^/api/[^/]*(?:/.*)?$')
LIMIT 100
If the regex is wrong can someone please correct it?
#standardSQL
SELECT *
FROM `bigquery-public-data.github_repos.files`
WHERE REGEXP_CONTAINS(path, r'/api/.*')
LIMIT 100
Meantime, note: title of your question is not consistent with question body - REGEXP_CONTAINS in WHERE clause just allows you to return all rows with searched pattern in path - but does not extract the pattern.
To extract pattern - you need to use REGEXP_EXTRACT(path, r'/api/.*') in SELECT statement.
I would like to build a regular expression in C# to match question mark except repeated or commented.
For example, if I have a string below
--???
??
asdlfkj --?
asldfjl -?
aslfldkf --?
aslfkvlv --??
?
-?
dklsafdlafjd = ?
, I want to match like below (between * character).
--???
??
asdlfkj --?
asldfjl -*?*
aslfldkf --?
aslfkvlv --??
*?*
-*?*
dklsafdlafjd = *?*
I'm developing SQL binding method using 2 parameters.
The first one is SQL, for example
select * from atable where id = ?.
SQL can have comment so I want ignore them.
The second one is parameter for SQL as Array to match sequentially;
Does anyone have good idea for it?
If you can negate this regex it should work for you:
(\?{2,}|(?<=--)\?)
I don't know what language you're working in, but you should be able to filter by line. Apply this regex as a predicate and either negate it or use a exclude function.
I'll leave those implementation details up to you.
As far as I found out, T-SQL has a possibility to check for regular expressions, via
PATINDEX.
My task is simple: I get a telecom-Type (phone for example). On a mapping table, a regex to validate this type is saved. So before saving, I'd like to check this regex.
So easy done:
-- Check the regular expression for phone
DECLARE #regExp nvarchar(255);
SELECT #regExp = tt.ValidationRegex
FROM Core.TelecomType tt
WHERE tt.Code = #DEFAULT_PHONE_TYPE;
Sadly, this always returns 0, even with wildcards with tries like this:
SET #regExp = CONCAT('%', #regExp, '%');
SET #regExp = CONCAT(#regExp, '%');
SET #regExp = CONCAT('%', #regExp );
On RegExr and oracle-side, the values seem to match, so is this a problem on the T-SQL? If yes, is there a workarround for this?
Thanks in advance
Matthias
Nope, sorry. PATINDEX doesn't let you match a regular expression, it works with the same kinds of patterns that are used with LIKE.
A quote from the documentation:
PATINDEX works just like LIKE, so you can use any of the wildcards. You do not have to enclose the pattern between percents. PATINDEX('a%', 'abc') returns 1 and PATINDEX('%a', 'cba') returns 3.
Unlike LIKE, PATINDEX returns a position, similar to what CHARINDEX does.
If you need regular expression matching in T-SQL, you'll have to rely on a custom CLR function/procedure. You can also check this to see if you can use it.