regex to match string not containg at least X characters [closed] - regex

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am looking for a regex to match a string that doesn't contain at least three characters [a-zA-Z]
Valid Strings:
abc12345
asd
abc12321!!
Invalid Strings:
aa!
111!!!a
!!!!!!b

I would use:
(?:[^a-zA-Z]*[a-zA-Z]){3,}[^a-zA-Z]*
You can find an explaination of this regex here.
matches:
abc12345
asd
abc12321!!
a85ug
83nj%#8n2
doesn't match:
aa!
111!!!a
!!!!!!b
a59&*#g9

You can check whether the following regex matches the string:
[a-zA-Z]{3,}
If it doesn't match then the string is invalid.
Basically the {3,} part of the regex says the the previous character class should be matched at least three times. It's pretty flexible in that you can specify a minimum number and a maximum number of times required for a match like so: {MIN,MAX} and if you omit either MIN or MAX then only the value specified is used (i.e. {3,} means at least 3, whereas {,3} would mean at most 3)

Related

How to start a RegEx statement at the 2nd position of a string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a string
.HACK G.U. VOL. 1 REBIRTH
I'm using a tool that allows me to specify a RegEx statement that can be used in a replace operation.
I want the RegEx to find all the periods "." that start after the 1st position. The replace operation should return the following.
.HACK GU VOL 1 REBIRTH
Thanks
The following will do the trick:
(?<!^)(\.)
per http://rubular.com/r/w1apzTZLPk
Since Javascript doesn't support negative lookbehind, this can't be done in Javascript, but there are alternatives as discussed in http://blog.stevenlevithan.com/archives/mimic-lookbehind-javascript
One approach in this case would be to capture the previous character and replace it with the same content as part of the replacement process, as in:
(.)(\.)
Note: You don't need to use a capture group for the matching of the literal . in either of the above. I just used that technique to highlight the match in Rubular.

Regex to match colon and numbers [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am writing regex to match the pattern like this.
abc:123-12-4
abc: It should be exact match including colon
123 Number match any length
- Exact Match
12 Number Match any length
- Exact match
4 Exact match
Any ideas how it can be done in a simpler way.
You can use this regex:
^abc:[0-9]+-[0-9]+-4$

Regex for two digit number followed by . for find and replace in vim [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to find out following string pattern in vim and replace it with some thing else. Can you please tell me regex for the same.
1.
11.
20.
21.
99.
basically one / two digits followed by dot.
I think you could do something like the following (I'm not very experienced with VI so there might be a better way)
:%s/\d\+\./MyString/gc
So that's essentially using \d\+\. to search for numbers appearing one or more times followed by a ..
MyString is your replacement string.
:%s is the substitute command, :s would just search the current line.
/gc looks for the match as many times as it appears on the line (g), and asks for confirmation before each replacement (c).
Tried this?
[^0-9][0-9][0-9]\.
Or have you tried it and it didn't work?
It has an issue though of three digits and a dot, i.e. "123." will also be captured
The regex for 1 or 2 digits followed by a dot is:
\<\d\d\?\.
The "word boundary" \< precludes 3 digits (and a dot), which would be allowed without it (the last two digits of a 3-digit number would match).
To replace using this tegex in vi:
s/\<\d\d\?\./foo/g

RegEx help: Matching a set of words unless they are preceded by specific keywords [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Looking for some regex help. I need to match words/phrases e.g. "confidential" "top secret" "sensitive" unless they are preceded by other words, for example: "contain" on the same line ..
"This email may contain confidential information" - this would not match
"Please see the attached confidential document" - would match because "contain" does not appear before the keyword "confidential" on the link.
I looked at using negative lookbehind but it's limited by width, so it would not work. In my case, the preceding words can appear several words before the keyword I am trying to match. Thanks!
You would think lookbehind, but it actually needs to be lookahead:
/^((?!contain).)*(confidential|top secret|sensitive)/
Because of the lookbehind fixed-wdth requirement.

Regular Expression to Match both Capital and Lower Characters [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am writing script for screening words within contents and replace it with *, if matched.
I am using the following simple regular expression for screening words like apple, banana
(\bbanana|apple\b)
It match all words banana and apple within content but not Apple or aPPle etc.
I want to write regular expression which match word regardless which character is capital or lower.
If i replace content to lower characters it will solve problem, but i want to keep content in original state.
You can try something like this:-
/[A-Z]{3}([0-9]{1,4})?|[A-Z]{1,3}/i
In your case:-
/\b(banana|apple)\b/i
the /i switch does case-insensitive matching:
/\b(banana|apple)\b/i
I also moved your word boundary markers outside of the alternation.