Regex remove spaces after 2 letters [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
What is the regex for no whitespaces after the first 2 letters? For example, the string starts with AB then is followed by an undetermined amount of numbers and/or letters but it cannot have any spaces.
(^[A][B][\S])

^[a-zA-Z]{2}\S+$
Edit live on Debuggex
^ denotes the start of the line
[a-zA-Z]{2} denotes exactly 2 letters
\S any character besides white spaces
+ one or more.
$ denotes end of string.
please read more about regex here and use debugexx.com to experiment.

It looks like you're using Python, so I'll just assume that.
^\w\w\S*
That's 2 word characters at the start of the line, followed by 0 or more non-whitespace characters.

Not sure what platform you're using, but you can try the following:
^[\d\w]{2}[^\s]*$
Should do the trick.
The [\d\w]{2} represents 2 letters or digits and then the [^\s] means no white space for zero or more characters afterwards. The caret and dollar sign notation force this to happen at the beginning of the string.
EDIT: Although the title of this question is remove white space your question seems to just ask for the regex for 2 letter/digit characters with no white space afterwards, which is what I answered. If you are looking for how to make a lookahead ignore my answer.

Related

Regex that does not repeat the same character 2 times in a row [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I need to make a regex to validate an amount in which it only accepts numbers, points (.) Optional, 1 comma (,) optional and that after the comma I have at least 2 more numbers, the farthest I've come is this
^(([0-9]{0,})+([.]?))+([,]{0,1}?)([0-9]{1,}?)+$
This works fairly well, the problem is that it allows me to put the period (.) Followed more than once for example (100 ... 000), this accepts it, but I need it to only accept one period (.) At a time, how do i fix it?
I need the regex to validate as follows
100 VALID
100.000,00 VALID
100. INVALID
100..00 INVALID
100, INVALID
100..000,00 INVALID
To prevent the same character (in this case a dot) appearing consecutively, use a negative look ahead anchored to start of input:
^(?!.*[.][.])<rest of regex>
In your case:
^(?!.*[.][.])(([0-9]{0,})+([.]?))+([,]{0,1}?)([0-9]{1,}?)+$
See live demo with test cases from question.
I'm not clear on what you actually want to match, but I don't need to understand that to answer your question, which was how to prevent the same character appearing consecutively.

Using Regular Expressions to find a line starting with specific number of spaces only [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 just want to ask how to create a regular expression that will read the line that starts with space, but the amount of starting spaces should not equal to 7.
Example (assume that the dashes are the starting point for every line):
- *THIS LINE HAS STARTING SEVEN SPACES.. SO THIS LINE WILL NOT BE DETECTED.
- *THIS LINE HAS STARTING THREE SPACES.. THIS LINE WILL BE DETECTED.
- *THIS LINE HAS STARTING TEN SPACES.. THIS LINE WILL BE DETECTED.
Thank you very much.
The following Perl regular expression matches what you want:
^(\s{0,6}|\s{8,})(?=\S)/
^ - Anchor at the start
\s - matches a single whitespace
\s{0,6}|\s{8,} - matches 0 to 6 or 8 and more whitespaces
(?=) - lookahead assertion
(?=\S) - Lookahead to see if there is exists a non-whitespace character

regex to match string not containg at least X 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 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)

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 - Without Special Characters [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm using regex to validate username
^[a-zA-Z]+\.[a-zA-Z]{4,10}^'
Unfortunately it doesn't affect if the the value contains special characters such as !##$%^&*)(':;
I would glad to get some help for Regex that contains:
Alphanumeric only (a-zA-Z0-9)
Length between 4 - 10 characters.
The conditions you specified do not conform to the regexp you posted.
the regexp you posted ^[a-zA-Z]+\.[a-zA-Z]{4,10}^ is erroneous I guess, because of the ^ in the end, it will never be matched to any expression, if you want to match with the ^ at the end of the expression, you need to escape it like this \^. but ^ alone means "here is the start of the expression", while $ means "here is the end of the expression".
Even though, it denotes:
It starts with alpha (at least 1).
there must be a '.' period character.
Now there must be at least 4 alphas.
The regexp you need is really is:
^[a-zA-Z0-9]{4,10}$
This says:
It starts with alphanumeric.
There can be minimum of 4 and maximum of 10 of alphanumeric.
End of expression.
Try this:
^[a-zA-Z0-9]{4,10}$