is it the right reqular expression - regex

i have following regular expression but it's not working properly it takes only three values after # sign but i want it to be any number length
"/^[a-zA-Z0-9_\.\-]+\#([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/"
this#thi This is validated
this#this It is not validating this expression
Can you please tell me what's the problem with the expression...
Thanks

If you want your regex to match "any number length" then why are you using {2,4}?
I think a better example of the strings you're trying to match might give others a better idea of what you want, because based on your regex it is a bit confusing what you're looking for.

Try this:
^[a-zA-Z0-9_.-]+#([a-zA-Z0-9-]+\.)+[a-zA-Z0-9]{2,4}$
The main problem is that you didn't escape the dot: \.. In regular expression the dot matches everything (mostly), making your regex quite liberal.

Related

Regular expression everything after a link

I am a complete regular expression idiot, just keep that in mind :)
I am trying to create a regular expression that will match link:xxxxxx where everything after link: is a wildcard.
Can i just do link:* or am I totally misguided?
link:.* should work correctly.
. matches any character, and you want to repeat it "0 to unlimited" times so you add *.
If you're new to regex, a good way to learn it is by using regex101.
For your problem, you can check out this regex101 example
(Note that I have also added the g modifier, which means that you want to select all matches, not just the first matching line)

Yet another password validating regular expression

I've gone through multiple examples to validate passwords via regular expression, but none of them quite fit what I am looking for. I've been using trial and error to build my own, but without complete success.
Here is the regular expression that so far is the closest match for what I am looking for:
(?=.*?[a-z]{3,})(?=.*?[A-Z]{3,})(?=.*?[0-9]{2,})[a-zA-Z0-9]{8,24}
The password should have three lowercase and three uppercase alphabets and two numbers. Password length should be between 8 and 24 characters. Special characters are not looked for, they can be used as long as other requirements are met.
The regular expression above matches ABCdef12 but does not match Ad1Be1Cf. How I should modify the regular expression so it also matches the latter example?
Use look aheads for the content assertion, and a simple regex for the length:
^(?=(.*[a-z]){3})(?=(.*[A-Z]){3})(?=(.*\d){2}).{8,24}$
See demo
I'm reasonably confident this this the shortest regex that will work for you.
(?=.{8,24}$)(?=.*?[a-z].*?[a-z].*?[a-z])(?=.*?[A-Z].*?[A-Z].*?[A-Z])(?=.*?\d.*?\d)(^.*$)
You can use this.It uses lookahead to test all conditions.
See Demo.
http://regex101.com/r/yX3eB5/9

Extract number + letter combination from string

I'm intrested in extracting c8127c6ea6a44c109b5e35ce61cd4b0096a9c6dc from a string that looks like this:
?t=c8127c6ea6a44c109b5e35ce61cd4b0096a9c6dc'
Here is my attempt at capturing the result in to a group.
?t=([a-e]\d+)'
Could anyone point me in the right direction, since this obviously isn't working?
http://regexr.com?383s6
You wanna put the \d in the [a-e] block and escape the ?:
\?t=([a-f\d]+)'
(and I assume you're looking for hexadecimal so it should be a-f?)
You can use this regex:
\?t=([a-e0-9]+)'
OR usig negation:
\?t=([^']+)'
In Ruby language you can try Rubular tool online to test your regular expressions.
\?t=(\w+)'
should do the match.

Regular Expression for set of number and repeated words

I need to find out the files similar to this
1234-JOHN-ebook.pdf
98749-RAJ-test.epub
Is there any regular expression that matches this format?
if the capitalization will allways be as in your examples then: \d+-[A-Z]+-[a-z]+\.[a-z]+
if not, this will do \d+-\w+-\w+\.\w+.
please notice you might need to escape the dashes (\-)

Regex for just only numbers

I haven't used regular expressions soo much, so I'm having difficulty . I want regex that only validates that the field contains digits, but that does not care about how many.
It should approve 77 and 2377? But do not approve 77.43 or xyz777.
How can I get this using regular expression? Is this expression ^[0-9]+$ ok or not
It's OK. You can just use ^\d+$ for all it matters anyway.
Yes, this regex is perfectly valid and does what you think it does, although if your regex engine supports this you could use \d, whichs stands for [0-9].
A simpler regex would be to invert your match and check for non-digit numbers: \D.