regular expression checking valid hostname port [closed] - regex

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I've searched thru various websites and here for one that works but none do.
I need a regex that validates a game server hostname is correct format.
Example:
gost.gflclan.com:27015
And also the normal ip:port
103.18.138.27:27015
The hostname version can also have numbers in the subdomain or main part. And always has 5 numbers in port on both.
I've currently got this but it only works for the ip:port and not the hostname one.
([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}:[0-9]{5})|([a-z].[a-z].[a-z]:[1-9]{5})
Thanks if you can help.

updated :
try:
[^\:]+:[0-9]{5}
dynamically match both:
103.18.138.27:27015
gost.gflclan.com:27015
little explaination:
[^\:]+ --- |> all chars till ':'
:
[0-9]{5} --|> exactly 5 numbers

There is a bit more cleaner code:
(([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})|(\w*.\w*.\w*)):[0-9]{5}

Live demo
You forgot the + after [a-z] and the dot must be escaped:
([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\:[0-9]{5})|([a-z]+\.[a-z]+\.[a-z]+\:[0-9]{5})

Related

regex: Check the first character AND match [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I'm working on a regular expression email validation assignment and it is working pretty well. I can match based on all the criteria I'm asked to. Here is my current pattern:
^([a-zA-Z0-9.\-\_\+]+)#([a-zA-Z0-9.\-\_\+]+)$
I also want to check that it begins with an alphabetic character. So I changed my pattern to this:
^[a-zA-Z]([a-zA-Z0-9.\-\_\+]+)#([a-zA-Z0-9.\-\_\+]+)$
And that works fine and only produces the match when the first character is alphabetic. BUT, the matches that are produced cut off the first character. So for example, if I try:
Billy#bobby.com
The match for the user-id before the # sign is coming back as "illy". I want it to come back as "Billy"
See the regex in action here: https://pythex.org/?regex=%5E%5Ba-zA-Z%5D(%5Ba-zA-Z0-9.%5C-%5C_%5C%2B%5D%2B)%40(%5Ba-zA-Z0-9.%5C-%5C_%5C%2B%5D%2B)%24&test_string=b2ill..%2B..DSD_y.23%40bobby.com&ignorecase=0&multiline=0&dotall=0&verbose=0
Nick gave me the help I needed. Here was my final pattern
^([a-zA-Z][a-zA-Z0-9.-_+]+)#([a-zA-Z0-9.-_+]+[a-zA-Z])$

Why does this regex pattern fail to match the string [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am trying to match a date string, and have tested out my pattern on regex101. I think I am following the regex rules, but I'm obviously missing something, and the pattern is not matching the string.
My regex pattern is: \s?(Mon|Tue|Wed|Thurs|Fri)day\s\d{0,2}(st|nd|rd|th)\s (January|February|March|April|May|June|July|August|September|October|November|December)\,\s\d{4}
The string I'm trying to match is:
Monday 16th October, 2017
Which can appear in the document with or without lead/trailing whitespace(s).
Why is the pattern not matching?
By copying your regex from your post, I saw there's a redundant space here:
(st|nd|rd|th)\s (January|
↑
I'm not sure if it's a formation problem or not. Anyway, remove it and you should be fine.
Suggestion:
Depending on the language you're using (was tagged Python), use a library that parses the string for you, instead of having this (ugly) regex.

Perl matching string with mix of alphanumeric,_ and any number of square braces [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
How do I match a string with " alphanumeric characters, underscore and any number of open and closed square braces ".
Example : " CDN_MBIT_hresp_s_reg[0]_MB_hresp_s_reg[1]bbjabs_chiansmokrs[6] "
I tried $line=~/[a-zA-Z0-9_/[/]]/;
This seems doesn't work.
P.S. This question is quite similar to Regex Matching Square Brackets
but not same
Thank you in advance.
Wrong slash used for escaping.
/[a-zA-Z0-9_\[\]]/
Alternatively, you could simply use
/[\w\[\]]/
Both of those match exactly one character. If you wanted to capture the string, you'd want
/([\w\[\]]+)/

Regex does not match url with www [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to write a regex that can match both following lines:
http://ficsgames.org/cgi-bin/show.cgi?ID=364189186;action=save
http://www.ficsgames.org/cgi-bin/show.cgi?ID=364189186;action=save
I've got this:
http:\/\/(www)?ficsgames\.org\/cgi-bin\/show\.cgi\?ID=[0-9]+;action=save
but it doesn't seem to work - http://regex101.com/r/vB2cM3/1
You are missing a dot . inside of your optional group.
(www\.)?
You're missing a \. in your (www)?
You forgot the . after www. (which needs to be escaped)
I've updated your regex link here:
http://regex101.com/r/vB2cM3/4

Notepad++ and regex [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am doing some test with Find in Notepad++ using regex. Here is my problem that I can't figure out why:
My text is:
abc/xyz/p234/s-sdf
The following regex matches well:
[a-z]+/[a-z]+(/p[0-9]+)/s-[a-z]+
But why the following regex (with an added '?') does not match anymore:
[a-z]+/[a-z]+(/p[0-9]+)?/s-[a-z]+
Am I right that in the last regex, the '?' means that (/p[0-9]+) can appear zero or one time?