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.
Related
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.
Trying to get a regex replace in an ansible role for update autoscales going.
In my CFT I have the following mapping:
DevRegionSettings:
us-east-1:
primaryZone: us-east-1a
# secondaryZone: us-east-1b
# autoscale is wrong at point of instantiation
amiAutoscale: ami-234sefsrwerwer21
amiDB: ami-12313123
amiCoord: ami-12312312
amiWeb: ami-13123123
amiWorker: ami-12312312
I want to replace just the value of amiAutoscale with the latest ami that I find earlier on in the role.
I'm a regex noob and cannot figure it out for the life of me.
Been playing around with some of the regex from this thread:
Regex to match key in YAML
But still cant get it to do what I want :(
Any help would be appreciated!
The ansible task I had running was as follows:
- name: Replacing ami in the Dev Cloudformation Template
replace:
regexp: '(^\s*(?P<key>\w+_amiAutoscale):\s*(?P<value>\d+))'
replace: "{{ latest_ami.image_id }}"
path: "$path_to_cft.yaml"
So a couple of issues with your regex:
\w+_amiAutoscale - The line amiAutoscale: ami-234sefsrwerwer21 does not have an _ before amiAutoscale
(?P<value>\d+) - ami-234sefsrwerwer21 is not a sequence of digits.
This worked for me, but may be too open of a pattern: (^\s*(?P<key>amiAutoscale):\s*(?P<value>.+))
Example: https://regex101.com/r/76VGlJ/1
- name: Replacing ami in the Dev Cloudformation Template
replace:
regexp: '(^\s*(?P<key>amiAutoscale):\s*(?P<value>.+))'
replace: "{{ latest_ami.image_id }}"
path: "$path_to_cft.yaml"
Your regex does not match because the regex expect to match 1+ word characters followed by an underscore \w+_ right after the starting whitespace characters ^\s* which are not in the data.
Also, in the named capturing group (?P<value>\d+) you match 1+ digits which does not match ami-234sefsrwerwer21
What you also might do for your example data is to use only 2 capturing groups and a character class in the second group to specify what you would allow to match:
^\s*(?P<key>amiAutoscale)\s*:\s*(?P<value>[\w-]+)
Regex demo
I am trying to match user names for accounts.
All out usernames only contain characters. However there are a few that contain "."
I am trying to write a expression that will match all username if they have special characters within them or not but have not go very far.
You can see from below i have 2 entry with 2 different account names. I need an expression that will match both.
So far i have this but keep getting tripped up on the special character.
Account Name:(\s\w*[.\D])
Can anyone help?
A security-enabled global group was created. Subject: Security ID: Account Name: testing Account Domain: Logon ID:
A security-enabled global group was created.Account Name: testing.testing Account Domain: Logon ID: New Group: Security ID: Group Name: Group Domain: SAM Account Name: SID History:
you can use Account Name:(\s[\w.]+)
[\w.]+ match 1 or more occurrences of a-zA-Z0-9_ and . character
if you need to match any special character then use Account Name:(\s[a-zA-Z]+.*)
[a-zA-Z]+ match at least 1 or more alphabet, although you can also use range {} if you have minimum characters for the username
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).
I'm looking to do a top ten list of the main pages of a bio but not the additional subdirectories. E.g.
/cr/johndoe
/cr/janesmith
but NOT:
/cr/johndoe/news
/cr/janesmith/dvds
/cr/santaclaus/galleries/1
etc.
I've started with filters=ga:pagePath==/cr/* but I'm not sure how to do the regex to get it to not go any deeper.
In order to match the /cr/something you can use the following filters:
filters=ga:pagePath=~/cr/[^/]*/?$
Or Url-encoded version:
filters=ga:pagePath%3D~%2Fcr%2F%5B%5E%2F%5D*%2F%3F%24
REGEX EXPLANATION:
/cr/ - matches the sequence of the characters literally
[^/]* - 0 or more characters other than /
/? - 0 or 1 / symbol
$ - matches the end of string.
If the URL starts with /cr, add ^ (start of string):
filters=ga:pagePath=~^/cr/[^/]*/?$
or Url-encoded:
filters=ga:pagePath%3D~%5E%2Fcr%2F%5B%5E%2F%5D*%2F%3F%24
You can use this:
^\/cr\/\w+$
DEMO