Regular expression: find abc.com except xyz.abc.com or #abc.com - regex

In Eclipse I want to find a string, and using the normal search results in hundreds of irrelevant results. So I'm trying to use regular expressions, but they don't give me the proper results up til now.
This is what I need: find "abc.com", but not "xyz.abc.com" or "#abc.com". To make it clear, it should return www.abc.com.
I've tried the following regex but I'm not sure if this is how it should be:
[^#xyz\.]abc.com

Using a negative lookbehind should suit your needs:
(?<!xyz[.]|#)abc[.]com
Every "abc.com" that is not preceded by "xyz." nor by "#".

Related

REGEX, searching for emails with a certain defined length, prefix & domain? (attempted but failed)

Hi i'm doing some infosec research and searching through text bins.
I'm using a text editor to search files and I'm wanting to search for email addresses with certain conditions. Text is comma-separated.
Say for example i know the email is 20 chars long and I know that the domain is gmail.com, and I also know it starts with t.
[tT](.{9})#gmail.com
If it was correct it should pick up for example: tqwertyuio#gmail.com and tzxcvb1234#gmail.com. Right?
I'm using emEditor which uses Boost Regex engine I think. This regex is just not working as it also returns anything that has that expression in it.
I've tried to use anchors, but they are not working. Perhaps its this engine. I would of thought i would go:
^[tT](.{9})#gmail.com$
But it's not working. Any help?? Thanks SO much i really just want to learn why i cant do this.
I believe you are looking for 20 characters long email which are NOT surrounded by alphabets or numbers. In that case, you can search for:
(?<!\w)[tT](.{9})#gmail.com(?!\w)
where \w is an alphabet or a number, (?<!\w) is negative lookbehind, and (?!\w) is negative lookahead.
In the Find dialog box, you can enter this regular expression, and make sure you select the "Regular Expressions" option.
You might also want to try the Filter toolbar with the same regular expression.

301 redierction, matching urls through regex. Matching dashes

I'm trying to match urls for a migration, however I can't seem to have a regex which matches it.
I've tried different expressions and using regex checkers to determine where exactly it's broken, but it's not clear to me
This is my regex
https:\/\/blog\.xyz\.ca\/EN\/post\/201[0-9]\/[0-9][0-9]\/[0-9][0-9]\/*\).aspx
I'm trying to match these kinds of urls (hundreds)
https://blog.xyz.ca/EN/post/2019/05/14/how-test-higher-education-test-can-test-more-test-students-and-test-sdf-the-test.aspx
https://blog.xyz.ca/EN/post/2019/05/14/how-test.aspx
https://blog.xyz.ca/EN/post/2019/05/14/how-test-higher-the-test.aspx
And remap them to something like this
https://blog.xyz.ca/2017/12/21/test-how-the-testaspx
I thought that I could match the dash section using the wildcard, but it seems to not be working and none of the generators are giving me a clear warning. I've tried https://regexr.com/ and https://www.regextester.com/
If I understand the problem right, here we might just want to have a simple expression and capture our desired URL components, according to which we would find our redirect rules, and we can likely start with:
(.+\.ca)\/EN\/post(\/[0-9]{4}\/[0-9]{2}\/[0-9]{2})(\/.+)\.aspx
and if necessary, we would be adding/reducing our constraints, and I'm guessing that no validation might be required.
Demo 1
or:
(.+\.ca)\/EN\/post(\/[0-9]{4}\/[0-9]{2}\/[0-9]{2})(\/.+)(\.aspx)
Demo 2

REGEX number not in a list failing with a long list

I have a list of the following numbers and want a Regular expression that matches when a number is not in the list.
0,1,2,3,4,9,11,12,13,14,15,16,18,19,250
I have written the following REGEX statement.
^(?!.*(0|1|2|3|4|9|11|12|13|14|15|16|18|19|250)).*$
The problem is that it correctly gives a match for 5,6,7,8 etc but not for 17 or 251 for example.
I have been testing this on the online REGEX simulators.
This should resolve your issue..
^(?!\D*(0|1|2|3|4|9|11|12|13|14|15|16|18|19|250)\b).*$
In your earlier regex you were basically saying eliminate all numbers that start with 0/1/2/3/4/9!
So your original regex would actually match 54/623/71/88 but not the others. Also the 11-19 and 250 in the list were rendered useless.
Although as others have I would also recommend you to not use regex for this, as I believe it is an overkill and a maintenance nightmare!
Also an extra note "Variable length look arounds are very inefficient too" vs regular checks.
I would do \b\d+\b to get each number in the string and check if they are in your list. It would be way faster.
You can use the discard technique by matching what you do not want and capturing what you really want.
You can use a regex like this:
\b(?:[0-49]|1[1-689]|250)\b|(\d+)
Here you can check a working demo where in blue you have the matches (what you don't want) and in green the content you want. Then you have to grab the content from the capturing group
Working demo
Not sure what regex engine you are using, but here I created a sample using java:
https://ideone.com/B7kLe0

Regular expression not working in google analytics

Im trying to build a regular expression to capture URLs which contain a certain parameter 7136D38A-AA70-434E-A705-0F5C6D072A3B
Ive set up a simple regex to capture a URL with anything before and anything after this parameter (just just all URLs which contain this parameter). Ive tested this on an online checker: http://scriptular.com/ and seems to work fine. However google analytics is saying this is invalid when i try to use it. Any idea what is causing this?
Url will be in the format
/home/index?x=23908123890123&y=kjdfhjhsfd&z=7136D38A-AA70-434E-A705-0F5C6D072A3B&p=kljdaslkjasd
so i just want to capture URLs that contain that specific "z" parameter.
regex
^.+(?=7136D38A-AA70-434E-A705-0F5C6D072A3B).+$
You just need
^.+=7136D38A-AA70-434E-A705-0F5C6D072A3B.+$
Or (a bit safer):
^.+=7136D38A-AA70-434E-A705-0F5C6D072A3B($|&.+$)
And I think you can even use
=7136D38A-AA70-434E-A705-0F5C6D072A3B($|&)
See demo
Your regex is invalid because GA regex flavor does not support look-arounds (and you have a (?=...) positive look-ahead in yours).
Here is a good GA regex cheatsheet.
To match /home/index?x=23908123890123&y=kjdfhjhsfd&z=7136D38A-AA70-434E-A705-0F5C6D072A3B&p=kljdaslkjasd you can use:
\S*7136D38A-AA70-434E-A705-0F5C6D072A3B\S*

Regular Expression Lookbehind and Lookahead numerical test

I am attempting to configure a regular expression that matches anything numerical value but 1211 so it will still match variations such as 1212 121 1122, 3411, etc
I am unable to test the below at http://regexpal.com/ as it does not seem to support ?
(1(?!2)|1(?!2)|(?<!1)2|(?<!2)1|[^1211])+|[0-9]{1,4})
Am I doing it right and also where can I test it?
EDIT
Please note that I need to implement in a rewrite module/filter.
You can simplify that regex a lot:
^(?!1211)[1-9]\d{0,3}$
As for regexpal, it's not working because your regex is invalid. You can tell right away because it as one more closing parenthesis than opening.
I suggest you take a simple route:
if (data != "1211"){
// your other regex here
}
you can test it using javascript, if you are familiar with it.