I am new to grails and so far i have only been able to use simple filters. I want to use filter in an efficient manner.
(I am using grails 2.4.3, with jdk_1.6)
I want to create a filter to allow accessing AppName/ and AppName/user/login and i could not get it right! I wanted to use regex but i am not getting it right!
i tried this
loggedInOnly(uri:'/**',uriExclude :"*.css|*.js|*image*|/|/user/login"){
before = {
println "### ###### #### #"
}
}
and i also tried to revers the regex parameter, but i am getting no luck! I searched all of google but i could not find a single thread to tell me how filter regex work!
i know i could create xxxx(controller:'*', action:'*') filter then use the controllerName and actionName parameters to check! But there gotta be a better way!
My question in a nutshell: How does regex work in filters?
First, take a closer look at the documentation. Notice that uri and uriExclude are ant paths and not regular expressions. Keeping that in mind if you look how ant paths function you will see they aren't capable of logical ors.
So, with all of that in mind it's back to using enabling regex and using the find attribute instead.
loggedInOnly(regex: true, find: '(.*.css|.*.js|.*image.*|\\/|\\/user\\/login)', invert: true){
before = {
...
}
}
Notice I hae used invert to have this filter apply to anything that doesn't match any of the patterns inside the find. Also, I wrote this off the top of my head so you may have to spot check the regular expression in your application (I did check it using groovy web console to make sure I didn't really mess up the syntax).
Hope this helps.
Related
We use serilog to output from our .nrt core app. We are using compact json to keep size down. In compact it seems to put the error key with an # sign;
"#l": "Warning"
I can’t seem to get a filter working it either returns no results or says error. I’ve tried many things but I’m sure this should work;
{ $.#l = "Warning" }
Anyone suggest where I’m going wrong.
I don't think you can use # in the selector. From the docs:
Property selectors are alphanumeric strings that also support '-' and '_' characters.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html#extract-json-log-event-values
One way to get around this would be to match the line as if it's not part of json.
For example, if your log line looks like this:
"#l": "Warning"
you could filter it out with:
[key="#l", colon, value=Warning]
I had the same issue. Most likely you used Serilog.Formatting.Compact.CompactJsonFormatter as me.
Implementing own ITextFormatter is a workaround because prefixes like # or $ are hardcoded inside CompactJsonFormatter.
I used CompactJsonFormatter as a basis, replaced there usage of #, $ by s_ and it works.
I tried for few hours to find the right syntax for making a regex query that returns reviews from 2-3 different projects but I failed and decided to crowdsource the task ;)
The search is documented at https://review.openstack.org/Documentation/user-search.html and mentions possible use of REGEX,... but it just didn't work.
Task: return all CRs from openstack-infra/gerritlib and openstack-infra/git-review projects from https://review.openstack.org
Doing it for one project works well project:openstack-infra/gerritlib
Ideally I would like to look for somethign like ^openstack-infra\/(gerritlib|git-review), or at least this is the standard regex syntax.
Still, I found impossible to use parentheses so far, every time I used them it stopped it from returning any results.
1) You don't need to escape the "/" character.
2) You need to use double quotes to make the parentheses work.
So the following search should work for you:
project:"^openstack-infra/(gerritlib|git-review)"
New to hubot/coffeescript and inheriting and existing script.
I googled and found some unhelpful stuff like this: Hubot matching on multiple tokens per line?
What I want to do is be able to parse parameters to my Hubot message. For example:
startPlaceOrderListener = () ->
robot.respond /order me (.*)/i, (res) ->
and then follow it with what you want to order.
I can obviously re-invent the wheel and parse res.match[1] myself, but hubot already seems to have some regular expression parsing built in for its own use and I was wondering if there's a way to leverage that for my own nefarious purposes.
It turns out the coffeescript has regular expressions built in. So
/order me (.*)/i
is straight coffeescript.
To match a regular expression you can do:
/order me (.*)/i.test("Bob")
Where the i can be left out if you don't want to ignore case.
To parse the input value in CoffeeScript you can do something like:
robot.respond /open the (.*) doors/i, (res) ->
doorType = res.match[1]
if doorType is "pod bay"
res.reply "I'm afraid I can't let you do that."
else
res.reply "Opening #{doorType} doors"
Im in the process of learning regular expressions but still cant really wrap my head around it quite yet. However I need to create one for Google Analytics and was hoping someone could help out.
Currently my Goal page is head-match:
/checkout/cart?complete
and funnel step:
/checkout/onepage
The problem is that the funnel step could be several different slightly different URLs. It could be:
/checkout/onepage
/checkout/onepage/index
/checkout/multishipping/login
/checkout/multishipping/billing
/checkout/multishipping/shipping
Can anyone tell me what the expression would be to "lump" those 5 potential URLs as the same thing? Also, what would I change my Goal url to if the potential outcomes could be one of the below examples:
/checkout/cart?complete=10000245 <-- (single order)
/checkout/cart?complete=10000245,10000246,10000247 <-- (multiship order)
I know I would have to escape the question mark first but after that Im not sure.
For your goal page you'll want to use the + ? and * operators.
/checkout/cart\?complete(=(\d+,?)*)?
For funnel you'll want the | and ? operators
/checkout/(onepage(/index)?|multishipping/(login|billing|shipping))
I'm trying to retrieve 2 fields from a web page. I'm using the following two patterns:
string paternExperience = #"Experience\s\:\s\<strong\>(?<Level>.*?)\<";
string paternAccount = #"account_value\""\>(?<Account>.*?)\<";
and the following method to retrieve values and it works.
Regex.Matches(pageBody, patern..., RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase | RegexOptions.Compiled |RegexOptions.Multiline);
I was trying to avoid using twice the method to retrieve 2 values, and I'm trying to create a pattern to get Level and Account in just one call of the Matches method. So I thought that something like the one below should work...
string paternBoth = #"Experience\s\:\s\<strong\>(?<Level>.*?)\< .* account_value\""\>(?<Account>.*?)\<";
But it doesn't work because I think that the two values are on diferent lines in html, so I added RegexOptions.SingleLine and now the method times out (the page has around 20kb).
Can you help me please with some advice? Thank you!
You could try putting those 2 values in 1 variable, then just check that variable with your regex.
I know it doesnt really make any sense but I try out things like that and sometimes it actually works.
Never had this scenario but I did have any simular problems in the past.
Might not be the best way. but sometimes making it work is more important then making it look pretty. ;)