/    Sign up×
Community /Pin to ProfileBookmark

Regex Help — bracketed character classes within non capturing groups?

Quite often I’ll create regex based filters to recognize and dispose of emails, containing origin IP addresses that are from a foreign system I’d never expect mail from. So, for example, if I’m trying to recognize an address within the range of

[CODE]185.220.0.0 – 185.255.255.255[/CODE]

I might compose a string like this…

[CODE]185.(?:22[0-4]|2[3-5][0-9]).[/CODE]

Granted I’m taking some shortcuts there.You couldn’t, for example, have a second octet be “259”. But still, if I get an origin address like “185.246.22.22”, I’d expect that string to be a match. The “185” is matched literally, the “.” is matched by the escaped “.“, and 246 should be matched by the second alternate in the non capturing group. There, the “2” is matched literally, the “4” falls within the range of the [3-5] group, and the “6” falls within the [0-9] group.

Now it “seems” to work, but that is an assumption based on the fact that once I get SPAM from a system, a dozen or more will usually follow. So if I install the filter and that spam source stops, its a good sign.

The trouble is, when I plug in my regex string and test IP string into the corresponding fields at regex101.com, it reports “Your regular expression does not match the subject string.” Am I doing something wrong, or am I not understanding how to use the online regex tester?

to post a comment
Full-stack Developer

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 17.2017 — Seems to work when I tried a few different strings on that site that should or should not match. I just copied/pasted it into the regex field (with no start/end delimiters) and then tried some different test strings.
Copy linkTweet thisAlerts:
@PeterPan_321authorApr 18.2017 — Seems to work when I tried a few different strings on that site that should or should not match. I just copied/pasted it into the regex field (with no start/end delimiters) and then tried some different test strings.[/QUOTE]

Hmmm! Well I'm glad to hear my methodology is good. As for the test site, I just realized that for whatever reason, it just doesn't work for me. using a regex string of just "1" and a test string of "1", it still reports no match. Maybe its a browser issue, but that's surprising as I'm using the latest firefox browser, and the page seems very responsive to every change I make. Its just that nothing matches anything! LOL! Oh well... I'll have to find another tester then. Thanks!

[ATTACH]17473[/ATTACH]

[canned-message]attachments-removed-during-migration[/canned-message]
×

Success!

Help @PeterPan_321 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...