My regex does not effective in spring-cloud-gateway - regex

I'm learning spring-cloud-gateway, when I practice predicates, I want to try some regex like followings:
spring:
cloud:
gateway:
routes:
- id: after_route
uri: http://www.google.com/
predicates:
- Cookie=token, hello*
I think hello* will matches hello,helloa,helloaaaaa..., but when I test by curl --cookies ..., it only matches hello, why helloa and helloaaaaa does not matches correctly?
Does regex in spring cloud application.yml need some changes?

I doesn't have anything to do with yaml or gateway just java regex
"helloaaaa".matches("hello*") // returns false.
But this works
"helloaaaa".matches("hello.*") // returns true.
Patter javadoc says X* matches X, zero or more times
So your regex would match "hellooooo"
"hellooooo".matches("hello*") // returns true.

Related

Regex: yaml finding match

I am trying to get a match in regex for all root yaml entries with their values. So only with entries with a value are considered (not matching any nested entries). I have been messing around with it but to no avail. thanks!
so with this example:
metadata:
url: "https://www.google.com"
booleanvalue: 'false'
tls:
host:
google_net: "google.net"
secret:
big_secert_net: "cert"
API_HOST: 'https://api.test.com'
DOMAIN: 'api.domain'
METRIC_ENVIRONMENT: 'test'
Regex would return this match:
booleanvalue: 'false'
API_HOST: 'https://api.test.com'
DOMAIN: 'api.domain'
METRIC_ENVIRONMENT: 'test'
grep -E '^[^\r\n]+:[^\S\r\n]+[^[{\r\n][^\r\n]*$' test.yaml
What I'm doing:
^[^\r\n]+: Match key at the beginning of the line
[^\S\r\n]+ Match inline whitespace (some implementations provide \h for this). There must be at least one whitespace characters after the colon.
[^[{\r\n][^\r\n]*$ Match the content. Ensure it starts with something that is not [ or { on the same line (those would start nested YAML objects). Then, match everything until the end of the line.

Symfony 3 access_control regex expression

I'm in Symfony 3.4, I want to allow access to some URLs for no authenticated users. For that I used Regex expression like bellow, but it gaves error of syntax in security.yml .
Expression: - { path: ^/link/[0-9]\{0,}/download/, role: IS_AUTHENTICATED_ANONYMOUSLY}.
[0-9]{0,} : for numbers.
Any help, thanks
I suggest matching 1 or more digits rather than 0 or more, and you should use roles, not role, to define the role:
path: ^/link/[0-9]+/download/,
roles: IS_AUTHENTICATED_ANONYMOUSLY
Note that \{0,} matches a literal {0,} string as you escaped the first open brace thus corrupting the limiting quantifier.

Using a wildcard in Regex at the end of a URL in GA

I'm a newbie at Regex. I'm trying to get a report in GA that returns all pages after a certain point in the URL.
For example:
http://www.essentialibiza.com/ibiza-club-tickets/carl-cox/14-June-2016/
I want to see all dates so: http://www.essentialibiza.com/ibiza-club-tickets/carl-cox/*
Here's what I've got so far in my regex:
^https:\/\/www\.essentialibiza\.com\/ibiza-club-tickets\/carl-cox(?=(?:\/.*)?$)
You can try this:
https?:\/\/www\.essentialibiza\.com\/ibiza-club-tickets\/carl-cox[\w/_-]*
GA RE2 regex engine does not allow lookarounds (even lookaheads) in the pattern. You have defined one - (?=(?:\/.*)?$).
If you need all links having www.essentialibiza.com/ibiza-club-tickets/carl-cox/, you can use a simple regex:
www\.essentialibiza\.com/ibiza-club-tickets/carl-cox/
If you want to precise the protocol:
https?://www\.essentialibiza\.com/ibiza-club-tickets/carl-cox(/|$)
The ? will make s optional (1 or 0 occurrences) and (/|$) will allow matching the URL ending with cox (remove this group if you want to match URLs that only have / after cox).

Jmeter Regex to return token

I have a JMeter HTTP Request that returns
{
"Token" : "VwAMVWXTakkdffdkEj1I9IiTr8DlYa89fK4yimmQNWSitIY1qBb1Qbs1FU9CfZHWMMlTed3hHOaBD7vJGNh9ZugFZuANtAomk17vIjg3Zgl1Fp0kulb6UTsbnkyyGNwNMGR"
}
in the response data. The string after the colon will change each time. I need this string to then be passed to another HTTP request. I have the rest set up but I am struggling with the regex, I get the default constantly.
Currently the regex looks like -
"Token":"(.+?)"
but doesn't work.
Can anyone help?
Thanks
Use a positive lookbehind,
(?<=\"Token\" : ).*
It matches all the characters which are just after to the string "Token" :
DEMO
OR
(?<=\"Token\"\s:\s\")[^\"]*
If you want the strings inside double quotes then use above regex.
DEMO
Below regex would capture the matched characters,
(?<=\"Token\"\s:\s\")([^\"]*)
Your return is JSON data, so the best option would be to handle it as JSON, which also would make your application far easier to maintain and evolve, when the data you are handling gets more complicated than just one attribute. Plus, you can handle it easily in JavaScript. Suggested reads:
Jmeter extracting fields/parsing JSON response
Use BSF Postprocessor to parse JSON response and save the properties as JMeter variables
Your regular expression needs to account for whitespace. I'd recommend using Regular Expression Extractor, which will make this alot easier for you.
Reference Name: FOO
Regular Expression: "Token" : "(.+?)"
Template: $1$
Use corresponding variable to access the match. ${FOO}
The variables are set as follows:
FOO_matchNr - Number of matches found, possibly 0
FOO_n - (n = 1, 2, etc..) Generated by the template
FOO_n_gm - (m = 0, 1, 2) Groups for the match (n)
FOO - By itself it is always set to the default value
FOO_gn - Not set at all
You can use regex ([^"]+) when you have received response from HTTP request.
Example:
"Token":([^"]+) --> Not required to add double quotation.

Search & Replace Request URI Filter in Google Analytics

I have 2 landing pages:
/aa/index.php/aa/index/[sessionID]/alpha
/bb/index.php/bb/index/[sessionID]/bravo
Because the sessionID is unique, each of the landing page will be tracked as different pages. Therefore, I need a filter to remove the sessionID. These are what i want to track:
/aa/index.php/aa/index/alpha
/bb/index.php/bb/index/bravo
I created the Search and Replace Custom Filter on the Request URI:
Search String: /(aa|bb)/index\.php/(aa|bb)/index/(.*)
Replace String: /$1/index.php/$2/index/$3
But i get the /$1/index.php/$2/index/$3 being reported on the dashboard the next day. So i tried /\1/index.php/\2/index/\3 but i got very strange results, //aa/index.php/aa/index/alpha/index.php/aa/index/aa.
Does anyone know how to reference the grouped patterns in the replace string?
My Solution:
i managed to solve it using Advanced Filter. My solution:
Field A => Request URI: /(aa|bb)/index\.php/(aa|bb)/index/(.*)/(.*)
Field B => -
Output to => Request URI: /$A1/index.php/$A2/index/$A4
I haven't used the Google Analytics regex engine, but it appears to me that \1 is referencing the entire match (which in other regex implementations is called \0), while \2 is the first group, \3 is the second group, and so on.
Your initial regex, however, looks incomplete--I think it should look as follows:
Search String: /(aa|bb)/index\.php/(aa|bb)/index(/.*)/(alpha|bravo)
Replace String: /\2/index.php/\3/index/\5
(Note that I'm not sure whether ? is supported in this regex implementation as the non-greedy modifier, but if it is, the above search string pattern might run a little faster if you change /.* to /.*?.)