I'm new to using regex expressions. I need to accept all subdomains like:
something.mysite.com
something2.mysite.com
anotherthing.mysite.com
What kind of regex can I put there if I want to do something like:
rack_env['SERVER_NAME'].match <regex>
You shouldn't be using a regex here. The way to go is:
rack_env['SERVER_NAME'].end_with?(".mysite.com")
Something along the lines of \.mysite\.com$ should work. http://rubular.com is a good resource for testing regular expressions.
[a-zA-Z0-9]+\.[a-z]+\.com
something.mysite.com //ok
something2.mysite.com //ok
anotherthing.mysite.com //ok
something2mysite.com //not ok
anotherthing.mysitecom //not ok
But It is risky because you.can.have.as.many.subdomain.as.you.want in the future
If it just the sub domains that are changing you could use:
/\w+\.mysite\.com/
Related
It's quite simple: I have
a datadog-dashbaord
a template-variable named env, which can have following values ['prod', 'test']
And I want to display metrics based on the env:
from-resource for test is unified-importer-test-sqsimportdlq11419573-xl6dn7o5wqtj
from-resource for prod is unified-importer-prod-sqsimportdlq11419573-prmohksrvxxg
So naturally I'd use following syntax:
unified-importer-$env.value-sqsimportdlq*
But this does not display anything, nor shows it any error.
This, however, works as expected: unified-importer-test-sqsimportdlq* (or unified-importer-prod-sqsimportdlq* respectively).
It looks like asterisk in combination with wildcards is not working.
Additionally, DD seems to dislike using two asterisks (as prefix and suffix):
How can I leverage the template-var env easily in this situation?
Well, it turned out that following solution works:
sum:aws.sqs.approximate_number_of_messages_visible{service:unified-importer AND env:$env.value AND queuename IN (unified-importer-test-sqsimportdlq86419573-al6dn7o5wqtj,unified-importer-prod-sqsimportdlq86419573-prmohksrvmxg)}
There's no way to use the template variable in the middle of a string, it can only go at the end. That would be a feature request to the Datadog team
I have had a good read through the doc on this but am still none the wiser.
http://graphite.readthedocs.io/en/latest/config-carbon.html
If we have a metric like so:
/var/lib/graphite/whisper/p1/p2/account/count_num_events.wsp
Does anyone know for sure exactly what part of this path graphite is applying the storage-aggregation regex to?
I assume that it will be just
"count_num_events"
and as such I could use a regex "^count.*" to match it. Or will it be applied to all or part of the rest of the path?
Cheers.
You are correct. that will be the thing you need. BUT note the metric will be using dots not slashes
p1.p2.account.count_num_events
So what you'll need in storage-aggregation is any of the following
*count_num_events
p1.p2.*.count_num_events
p1.*.account.count_num_events
*.account.count_num_events
*.count_num_events
*count_num_events$
p1.p2.account.count_num_events
I have finally got round to doing some testing on this.
Thanks for the answer Fred S I wish I had seen the response before doing the testing, would have helped.
So the answer is that graphite matches on the full metric name which is . separated. Which for the example metric file:
/var/lib/graphite/whisper/p1/p2/account/count_num_events.wsp
Would be:
p1.p2.account.count_num_events
So the most strict regex you could do would be:
^p1\.p2\.account\.count_num_events$
I have the following in my routes.php:
Route::get('test/foo', 'TestController#index');
Route::get('test/bar', 'TestController#index');
Route::get('test/baz', 'TestController#index');
and I am trying to reduce this to the following:
Route::get(either 'test/foo' or 'test/bar' or 'test/baz', 'TestController#index');
One documented approach that would sort of apply here, is to place a regex constraint to the route:
Route::get('test/{uri}','TestController#index')->where('uri', 'regex for foo, bar, and baz...');
However, this solution would be ugly. Isn't there an elegant way to just express
{uri} in foo,bar,baz
in Laravel's language? Otherwise, what would the regex look like?
Thanks!
P.S. I've read this, but it didn't apply to my case with 3 routes.
I'm not sure why do you say that RegEx is ugly. I basically think RegEx is one of the most powerful tools.
In your case, I think the below snippet should do the job:
Route::get('user/{name}', function ($name) { // }) ->where('name', '(foo|bar|baz)');
The (foo|bar|baz) RegExr will match any of these string: 'foo', 'bar', 'baz'. So, if you need more, just add pipe (|) and add the needed string.
I'm building the new version of a website and I have to take charge of older urls looks like :
http://website.com/article_title_rewrited-article_id.html
Actually, I try to work about something like that :
app.get('/:title\-:id([0-9]).html', function...);
But of course it fails !
Can I do this type of rewriting using expressjs, or have I to use another method to port the url rewriting ?
Thanks by advance !
I see you are trying to use the Express url route parser as well as REGEX expressions, unfortunately this doesn't work, you have to use one or the other.
Remove the string and place with a REGEX pattern. Then the groups in the REGEX expressions will be available at req.params[0] and req.params[1].
app.get(/(.+)\.html/, function(req, res, next) {
res.redirect(req.params[0].substring(0, req.params[0].length - 5)); // -5 for length of '.html'
});
I believe that should (untested) sort it generically for all .html extensions if that can be a helpful guide :)
Can you help me with expression for array: ["232","2323","233"]
I try this: /^\[("\d{1,7}")|(,"\d{1,7}")\]$/
But this expression is not working properly.
I use ruby(rails).
This would validate the array structure well, blocking an entry like [,"123"]
^\[(("\d{1,7}")(,"\d{1,7}")*)?\]$
You may try this ( though it may allow leading ,):
^\[(,?"\d{1,7}")*]$
Try this: /^\[("\d{1,7}")(, ?"\d{1,7}")*\]$/