Get URL-prefix like matching, using RegEx in Stylish? - regex

I am coding custom CSS for Facebook using Stylish.
Everything goes well except that I need to have some custom values under the condition of URL-suffix. The only thing that comes close is URL-prefix which is the exact opposite.
So I was wondering if I could do something like:
Detect if URL is like either:
www.facebook.com/*/posts or just */post
where * could be any value.
Is it possible to do this through RegEx?
I googled it but I couldn't make anything out of it.
I want to apply some CSS code only when viewing some individual Facebook posts, and the URLbar shows:
www.facebook.com/User/Posts/PostID.php
Therefore, I would only like to detect if Post or post/postID.php exists and apply the style.

The below regex would match the links which contain the string /posts,
(?=.*?\/posts).*
DEMO

Related

How to exclude the last part of a variable string using regex

I am currently making a bunch of landing pages that use similar URL structure, but each URL varies in number of words.
So it's something like:
http://landingpage.xyz/page-number-five
http://landingpage.xyz/page-number-fifty-four
http://landingpage.xyz/page-for-a-different-topic
and for the sent page I just postfix -sent like this. The reason I am not adding it as /sent is because the platform I am using handles URLs this way.
http://landingpage.xyz/page-number-five-sent
http://landingpage.xyz/page-number-fifty-four-sent
http://landingpage.xyz/page-for-a-different-topic-sent
Now I found it easy to make a regular expression that identifies all the sent pages which is let's say:
\/([a-z0-9\-]*)-sent
The thing is that I am not sure how to identify the ones that are not sent. I tried using a similar regular expression using something like this, but it's not working as expected:
\/([a-z0-9\-]*)(?!-sent)
What's the best way to design the regex for this? Or I am approaching it in the wrong way?
A lookahead should be considered where there are some characters left to match. So one at the end of regex doesn't look for anything. As long as I'm not sure whether or not your environment supports lookbehinds, this should be a workaround:
\/(?!.*-sent\b)([a-z0-9\-]*)

Regex random number in google tag manager

I'm trying to use regex within google tag manager(GTM) to see if there is a match on a random number. In this way we can use sampling on certain tags. Only problem, the regex within GTM looks like it has a mind of it own. Simple example.
Google tag manager generates the following number on the gtm.load event: 112677907
My regex(on that same event) looks like follows:
matches RegEx 01$|02$|03$|04$|05$|06$|07$|08$|09$|10$|11$|12$|13$|14$
Surely this needs to have a match. GTM thinks otherwise... Does anyone have clue?
I saw what was going wrong. In the debugger of GTM you can see the value of you're variables. Though it looks te random number als get triggered in the tag itself. So I was actually looking at the wrong variable. So the RegEx was working fine.

Google Form Validate a specific URL Regex

I am creating a google form and trying to create a regex on of the fields because I need them to enter a profile link from a specific website. I'm a beginner with regex and this is what I have come up with:
/^(http:\/\/)?(steamcommunity\.com\/id\/)*\/?$/
But when I go to enter a test link such as: http://steamcommunity.com/id/bagzli it fails it. I don't understand what is wrong about it.
You missed a dot (meaning any character) after the (/id\). Try this:
/^(http:\/\/)?(steamcommunity\.com\/id\/).*\/?$/
^-- added
The ultimate goal of what I was trying to accomplish is to ensure that certain text was entered in the box. I thought I had to use Regex to accomplish that, but google forms also has "Text Contains" feature which I made use of to solve my problem. The regex by Zoff Dino did not work, I am not sure why as it seems completely correct.
I will mark this as resolved as I managed to get my answer, even if it was not via regex.

Regular Expression for finding JavaScript accessing custom attributes

I'm fixing our web application to be browser compatible with Internet Explorer 10 (non-compatibility mode) and have run into a couple if issues. There is a lot of JavaScript that access a custom attribute of an element, which does not work in Internet Explorer 10 (regular mode). I've fixed most cases by using element.getAttribute("customattribute"). The problem is, there is quite a bit of JavaScript and I do not know all the places that a custom attribute is trying to be obtained. I've working on finding all occurrences by using a regular expression. Basically, I want to find anyword, followed by a dot (.) followed by anyword except attributes like id, name, checked, etc, followed by a space or equal sign. This is what I've come up with so far.
(\w)\.(?!attr|index|all|id|value|className)(\w)([ \t]|=)
The words attr, index, all, id, value and className are all being returned though. Is there a better way (or correct way) to achieve this?
I used the following modification to obtain the things you are asking for:
(\w*)\.(?!attr|index|all|id|value|className|getElementById)(\w*)
However there are a lot of dot phrases caught (e.g. "document.getElementById", "xmlhttp.open") which you don't want. So whitelisting things you do want may be helpful as well:
style\.(?!attr|index|all|id|value|className|getElementById)(\w*)
Tested at: http://gskinner.com/RegExr/ with a sample of JavaScript code. Without more information on the JavaScript code itself there are too many I can suppose to exclude or do the opposite if there are too many custom ones to I want to find.

Why isn't DownThemAll able to recognize my reddit URL regular expression?

So I'm trying to download all my old reddit posts using a combination of AutoPagerize and DownThemAll.
Here are two sample URLs I want to distinguish between:
http://www.reddit.com/r/China/comments/kqjr1/what_is_the_name_of_this_weird_chinese_medicine/c2med97
http://www.reddit.com/r/China/comments/kqjr1/what_is_the_name_of_this_weird_chinese_medicine/c2meana?context=3
The regexp I'm trying to use is this: (\b)http://www.reddit.com/([^?\s]*)?
I want all my reddit posts downloaded, but I don't want any redundancy, so I want to match all of my reddit posts except for anything with a question mark (after which there's a "context=3" character).
I've used RegEx Buddy to show that the regexp fits the first URL but not the second one. However, DownThemAll does not recognize this. Is DownThemAll's ability to parse regexp limited, or am I doing something wrong?
For now, I've just decided to download them all, but to use a renaming mask of *subdirs*.*text*.*html* so that I can later mass remove anything containing the word "context" in its filename.
Reddit does have an API, you might want to take a look at that instead, might be easier.
https://github.com/reddit/reddit/wiki/API
EDIT: Looks like http://www.reddit.com/user/USERNAME/.json might be what you want