Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
What would be a regex for matching "[d-n]", where n is any number?
i.e.
Test_4_[d-123] - returns ideally only 123
or, if I can return [d-123] I could make some string formatting.
(?<=\[d-)\d+(?=\]) will return 123 from Test_4_[d-123].
You give very little information as to how you want stuff matched.
A very simple solution could be:
\[d-(\d+)\]
From left to right:
\[ will match the literal character [
d- will match just d-
(\d+) will match any digit one or more times. It is in parenthesis, which makes it a capture/match group. This should mean that if you are using a regex tool/library, you should be able to retrieve the "first match group" and you should retrieve just 123.
\] will match the literal character ]
I can only suggest using a website like https://regex101.com/ which can help in creating regular expressions.
Related
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 last year.
Improve this question
I wanted to find a regex pattern that checks if there's one letter in between the space.
For example: John A Doe
I want to capture only John Doe (without A) but there's 50/50 chance that the data will not contain middle initials.
I made this pattern ([A-z]* [A-z] [A-z]*|[A-z]* [A-z]*) but it captures also the middle one.
I'm sorry for the vague title cause I'm really confused rn.
Edit: I forgot about the [A-z] captures upto 122 in ascii table. I replaced it with \w as well.
Perhaps code like:
var m = Regex.Match(input, #"(?<f>[a-z]+)( [a-z])? (?<l>[a-z]+)", RegexOptions.IgnoreCase);
Console.WriteLine(m.Groups["f"].Value);
Console.WriteLine(m.Groups["l"].Value);
You'll need to capture the first and last names separately and stick them back together later
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 want to create a regular expression to check the following string pattern, I tried following these tutorials but it's still confusing. Any help is appreciated.
Type: In Folder
(T or t)ype(spaces or no space):(spaces or no space)(i or I)n(spaces or multiple space)(f or F)older
So following your desired pattern at the end of your question:
(t|T)ype\s*:\s*(i|I)n\s*(f|F)older
The above pattern should match your string. Mind you, \s* is zero to unlimited spaces, which means it would match on the string you provided even if there were no spaces present; if there will always be at least one space present, you can replace them with \s+
Hope this helps!
(T|t)ype\s*:\s*(I|i)n\s*(f|F)older
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 4 years ago.
Improve this question
I have a string “banaanapplebanaanappleapplebanaanappleappbanaanaapple”,
1. If I want to extract “apple”, the below resultset applys well.
RegEx : apple
result : "banaanapplebanaanappleapplebanaanappleappbanaanaapple”
If I want to extract “banaana” the below query works well.
RegEx : banaana
result :
“banaanapplebanaanappleapplebanaanappleappbanaanaapple”
I want to match “apple and banaana”
RegEx : banaana
result :
“banaanapplebanaanappleapplebanaanappleappbanaanaapple”
I want my resultset to contain only two matches of the apple..
How can I achieve this with regex?
You actually need an alternation operator with capturing group.
banaana|(apple)
The idea is, first banaana would greedily match all the banaana strings. | OR (apple) capture apple strings only from the remaining characters. So this won't overlap with banaana strings.
Example
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How can I write a regular expression that would allow alphabets,numbers,space and following special characters ,-/.#\
For example it should accept these two:
916 1/2 W 6#TH ST, Davenport, IA, 52802-3431
100-1/2 Duke Street, 22314
I have little knowledge of writing Regular expressions and I'm currently asked to modify a code so plz excuse me for posting this question. Learning regex would take time and I dont have it at hand
You asked alphabets,numbers,space and following special characters ,-/.#\
Alphabets, numbers : [a-zA-Z0-9]
Space : [ ]
Special chars : [,\/.#\\-]
From end to end : ^$
Any length : *
Shuffle it together : ^[a-zA-Z0-9 ,\/.#\\-]*$
Make it C# friendly: #"^[a-zA-Z0-9 ,\/.#\\-]*$"...
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 8 years ago.
Improve this question
I need one white space only in my regular expressen.
How should I create the code that validate if one white space is availabe in the string value?
I'm not sure exactly what you mean but I'm guessing you want to check for exactly one whitespace, but any number of non-whitespace characters:
#"^\S*\s\S*$"
Example code:
Regex regex = new Regex(#"^\S*\s\S*$");
Console.WriteLine(regex.IsMatch("Hello, world!"));
Console.WriteLine(regex.IsMatch("This contains three spaces."));
Console.WriteLine(regex.IsMatch("Two\nlines."));
Output:
True
False
True
Other variations
To check if the string contains exactly one whitespace only (no other characters):
#"^\s$"
To check if the string contains at least one whitespace:
#"\s"