This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 2 years ago.
I'm searching for a Regex to avoid letting user to enter a string with only a single ? character.
Here are examples of what I want to achieve:
? Not Ok (I want to avoid letting this)
?a Ok
a? Ok
?? Ok
??? Ok
This matches either any one- character string which is different from ? or any string with at least two characters
^([^?]|..+)$
Related
This question already has answers here:
Regular expression for alpahbet,underscore,hyphen,apostrophe only
(5 answers)
Closed 2 years ago.
I want to make a pattern for input.
I have this [A-Za-z]|-, but if I type dsadsa$ this, the special characters still allowed and I need only
big and small letters, and - .
You can escape - character:
[A-Za-z\-]
Your expression should be like following:
([A-Za-z\-]+)
([\w-]+)
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
I have this string
copiaElementos = "c'8 d'8 a8"
And when I do Regex.Matches(copiaElementos, "8.").Count() it returns 2
why is that? I don't understand, can anyone please give me a hand?
Thank you, best regards
That is because the . mathes one character. means you are matching an 8 followed by any charactrer, and there are exactly two of those (a space is considered a character too). Because the last one has no characters after it.
if you want to count the 8s in the string you should do Regex.Matches(copiaElementos, "8").Count(). Remember every character, even a space has its own meaning in regex.
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I need to capture strings containing only one dot. String will mostly contains domain names like
test.com, fun.test.com, lesh.test.com.
I need to check only the first one and to ignore the string that has more than one dots.
How can I do this using regex?
Like this :
^[^.]+\.[^.]+$
Check explanations https://regex101.com/r/mn7Ccr/1
This question already has answers here:
My regex is matching too much. How do I make it stop? [duplicate]
(5 answers)
How to extract a substring using regex
(14 answers)
Closed 3 years ago.
I'm trying to find the word: <*hasburnt*> in the string below using the this regex: <\*.*(bur).*\*>
But it gives me both <*hasburnt*> <*electrical*>. How do I just get <*hasburnt*> ?
bench testedstarter, starter just makes noise, and <*hasburnt*>
<*electrical*> smell.
Try this: /<.*?(bur).*?>/
Regex101 demo
The reason for ? here is because .* tries to match as much characters as possible, so it also matches <electrical. .*? makes it lazy - trying to match as little as possible, and as such ending the match at <hasburnt>.
EDIT: using ? for the first .* would make <hasburnt> independent of positions of similar strings.
This question already has answers here:
What is a word boundary in regex?
(13 answers)
Closed 4 years ago.
string sample: "universal studios japan"
How do i make so that it matches with "japan universal studios"
AND also with "japan univer"
Right now I'm using the following to regex :
^(?=.*\bjapan\b)(?=.*\buniversal\b)(?=.*\bstudios\b)
which works but
^(?=.*\bjapan\b)(?=.*\buniver\b)
does not work. It has to be a complete match for the second word..
^(?=.*\bjapan\b)(?=.*\buniversal\b) would work..
What changes do i need to make?
^(?=.*\bjapan\b)(?=.*\buniver(?:sal)?\b)
You can make sal optional.
See demo.
https://regex101.com/r/wDUC7j/1