RegEx to match sub-string of a URL - regex

I am in the need of a Regex to match single post permalink but not pagination page, category or certain exception pages (RSS feed page, contact page, etc):
valid => http://anysitexxxx.com/a-single-post/
invalid => http://anysitexxxx.com/
invalid => http://anysitexxxx.com/category/running
invalid => http://anysitexxxx.com/category/running/1
invalid => http://anysitexxxx.com/page/2
invalid => http://anysitexxxx.com/page/3
invalid => http://anysitexxxx.com/feed -> sample of certain execption
This is intended for Google Analytics URL goal matching purposes- can someone with this experience help me? Thanks

You will need to use negative lookahead with the exceptions you don't want
http:\/\/anysitexxxx\.com\/(?!category|page|feed).+
Demo

Related

Fail2Ban regex for Drupal log not matching

I am trying to match and ban certain patterns in my drupal logs (drupal 9).
I have taken the base drupal-auth regex, created a new conf and tried to amend it to my requirements but I seem to be failing at the first hurdle. This is the code that will give me anything that has the type 'user' and this is filtered by the user\ in the code below, just before the <HOST> block:
failregex = ^%(__prefix_line)s(https?:\/\/)([\da-z\.-]+)\.([a-z\.]{2,6})(\/[\w\.-]+)*\|\d{10}\|user\|<HOST>\|.+\|.+\|\d\|.*\|.+\.$
If I want to search exactly the same pattern, but with say 'page not found' or 'access denied' instead of 'user' what do I need? I cannot seem to get it to match the moment the type has a space in it. It seems such a simple thing to do!
I am using fail2ban-regex --print-all-matched to test.

regex to validate router parameter not working

I want to validate if an email is being send correctly in routes, however it isn't working when I put a regex condition (like explained here)
Basically, I added:
Route::group([
'namespace' => 'Auth',
'middleware' => 'api',
'prefix' => 'auth'
], function () {
Route::post('login', 'AuthController#login');
// ...
Route::get('checkemail/{email}', 'AuthController#check_email')->where('email', '#.*?\.');
});
even if I pass a valid email I get an 404 not found. what can I do to make the code works well?
It looks like you're missing .+ before # in your regex.
Edit: I forgot to mention, you can put the same thing after #, and the current regex seems like it's wrong as well. I won't go into it, but validating email should not be complicated for a lot of reasons.

Vue.js - Element UI - Form validation regexp

I'd like to validate a form using vue-js 2.3 and element-ui
Apparently, they use async-validator to validate the form. The documentation is here.
Example
https://jsfiddle.net/skd3nyqh/
Problem
Uncaught Error: Unknown rule type D*([2-9]d{2})(D*)([2-9]d{2})(D*)(d{4})D*
I do not know how to validate a field with regexp. I find the documentation not explicit enough on that topic.
From the documentation.
Pattern
The pattern rule property indicates a regular expression that the
value must match to pass validation.
Use
{required: true, pattern:/\D*([2-9]\d{2})(\D*)([2-9]\d{2})(\D*)(\d{4})\D*/, message: 'Please input phone', trigger: 'blur' }
Updated fiddle.

Rails 4 - Restful index action for for both get and post

I made 'search' action available for both get and post
resources :wba_partners do
collection do
match "wba_partners/search" => "wba_partner#search", via: [:get, :post]
end
end
for POST method it works as it should be '/wba_partners/search'.
for Get method it is throwing error:
ActiveRecord::RecordNotFound in WbaPartnersController#show
Couldn't find WbaPartner with 'id'=search
Any idea how it can be solved? Thanks.

Rails 3 routes with extended regex :constraints - bug?

I have the following route in my Rails 3 app.
post 'games/:id/:task/:card_id' => 'games#perform', :as => :perform
...which allows, obviously, such requests as button_to("Foo", {card_id=>2, :action=>:perform, :task=>"foo"}), mapping to the URL /games/1/foo/2.
I'd like to restrict the set of tasks the route matches. The Rails API docs indicate that "Constraints can include the ‘ignorecase’ and ‘extended syntax’ regular expression modifiers". However, the following works as expected:
post 'games/:id/:task/:card_id' => 'games#perform', :as => :perform, :constraints => {:task => /(foo|bar)/}
But the following doesn't:
post 'games/:id/:task/:card_id' => 'games#perform', :as => :perform, :constraints => {:task => /(foo|
bar)/x}
In the latter case, the button_to link above produces the URL: /games/perform?card_id=2&task=foo.
Is this a bug, or am I doing something wrong?
Yeah, there's a bug in the RegexpWithNamedGroups processing for Ruby 1.8.x because it fakes the named regexp groups syntax of 1.9 in a way that is incompatible with regexp modifiers.
The problem here is that with 1.8 Rails uses a simple index of the paren group within the regexp to map to the name. When you add a modifier to a regexp, internally this creates an additional group which throws the index off by one.
Workaround right now is to use 1.9, or no modifier.