I need a regular expression to allow just numeric and (.-/)
It should allow something like that:
011.235673.98923/0001-12
The pattern you're looking for, that matches only those strings with numbers, ., -, and /:
^[0-9\.\-\/]+$
If you have a specific language you're looking to implement this I may be able to help you.
You're looking for ^[\d./-]+$
to be sure it's in right order and require every part
^(\d+)(\.(\d+))*(\/(\d+))*-(\d+)$
edit: Forgot to add the / sry
^[\d./-]*$
does this. What regex flavor are you using? Perhaps it needs to be adjusted for it.
How about something like
(\d|\.|\-|\/)*
Does it matter how many - and . and / you get? Does the order matter?
You can use this item
[^1-9]
To view its performance, refer to the following link
regex101
This should do the work
^[\d\.\-\/]+$
If your sequence to be matched isn't at the start of the string, you can skip the ^. Similarly, $ is required to match sequence at the end of string.
Related
I am working with regular expressions, I need to create an expression for validating strings against the following scenario:
Solution.<word1|word2|word3>.<word4|word5>.anyword.(any word containing proj in it)
I tried
Solution.\b(word1|word2|word3)\b.\b(word4|word5)\b.(.*).\b(.*proj)\b
But this allows strings like Solution.word1.word4.blabla.blabla.csproj, meaning it allows anything before the proj because of the .*.
Can someone help me with this??
Looks like you need this regex:
Solution\.(word1|word2|word3)\.(word4|word5)\.([^.]+)\..*?\bproj\b
RegEx Demo
You might want to try (need to escape the . and allow capturing group to have chars except .):
Solution\.\b(word1|word2|word3)\b\.\b(word4|word5)\b\.([^\.]*)\.\b([^\.]*proj)\b
It's hard to consider the actual strings you want to allow without more clarification.
You can try the following regular expression.
Solution\.word[123]\.word[45]\.\w+\.\w*proj\b
I have tried many combination of
\d{1,2}:\d{2}
to validate a period of time(ie: 0:33 or 12:33).
Therefore, for the most part the above expression works, but I also need to
1) validate ":33" and
2) invalidate "00:33a"
I have googled around and try to combine \s* but it still does not satisfy both conditions.
Any help is appreciated.
If you want to match only valid times (e.g. 23:59, but not 25:03 etc), you could try the following regular expression:
^([01]?[0-9]|2[0-3]):[0-5]?[0-9]$
I believe you just need to specify the beginning ^ and end $ string signifiers
^\d{1,2}:\d{2}$
That way 00:33a will invalidate
Looking at your question more closely and expanding on Gijs's answer, this may be what you're after...
^(?:[0-9]?|(?:[0-1][0-9])?|(?:2[0-3])?):[0-5][0-9]$
Allows for ':mm', 'h:mm' or 'hh:mm'.
I'm not sure how universal the (?: non-capturing group is - I'm accustomed to it from .Net.
I need to filter, 213.190.149.120 - 213.190.149.127 inclusive
Anyone know if there is a regular expression I can use to do this?
Thanks,
C
If you need a strict regular expression, don't forget that . matches any character, so
^213.190.149.(1(2[0-7]))$
will match "213d190c149a125" for example, which is not what you want.
On top of what, you're capturing each of the 3 digits, which is resource consuming for no apparent reason. A simple yet stricter regex would be closer to what #Marc suggested:
^213\.190\.149\.12[0-7]$
Don't know how Google Analytics expects the expression but this would be a valid regualar expression for your request:
213.190.149.12[0-7]
Okay.Found this link...
and it outputs...
^213\.190\.149\.(1(2[0-7]))$
Very handy for anyone else looking to do this.
Looking for a regular expression to find the words: David and 07888998 per line, They can be found more than once.
This is the data:
abcasdahadMichaeljkhdkjh 0888881SNADNA
SSMA,DAAASDDDavidjhsjdha007888998
asdsdASDDDavidjhsjdha==007888998asffafa
asdsdASDDDavidjhsjdha==007888995asffafa
SSMA|DAAASDDDaidjhsjdha007888998
The regular expression should find 2 matches. Line 2 and Line 3.
Any help is appreciated. Thanks
Since the order does not matter, you can use positive lookahead assertion (assuming the language/tool you are using supports it) as:
^(?=.*David)(?=.*07888998).*$
Rubular link
If order matters, then /David.*07888998/ will find the matches you want.
If it doesn't matter and you want to make sure they both appear at least once, you can just "or" together two regexes that account for either order: /(David.*07888998|07888998.*David)/
This should work:
/(David.*07888998)|(07888998.*David)/
More ways:
^(?=.*David)(?=.*07888998)
or
(?:.*(?!\1)(David|07888998)){2}
or
(.*(?!\2)(David|07888998)){2}
How do I determine the file extension of a file name string?
lets say I have
I'm.a.file.name.tXt
the regex should return tXt
something like \.[^.]*$ should do it
You probably don't need regex - most languages will have the equivalent to this:
ListLast(Filename,'.')
(If you do need regex for some reason, Scharron's answer is correct.)
What language is this in? It's quite possible you don't want to actually use a regex - assuming the name is a String you'll probably just want to do something like split it over periods and then choose the last segment. Okay, that's sort of a regex answer, but not a proper one.
/^(.*?)\.(.*)$/
The '?' makes it greedy. Your result will be in the second group.