Regular expression for specific special characters [closed] - c#

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 ,\/.#\\-]*$"...

Related

Regular expression generation for a string [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 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

RegEx match specific pattern in a text "[d-n]" [closed]

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.

c# RegEx, how to filter the resultset of regex [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 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

How do I match a string starting at a specific position in the string? [closed]

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 5 years ago.
Improve this question
What is the regex for matching a date starting at the 4th position? I want it to return just the date and not the whole match. This is what I have.
^.{4}[2-9][0-9]{3}[0-1][0-9][0-9]{2}
DCSG20170406090204-FQI-046.TOT 04-FIC-046 00060Y000815050.562500G
DCS120170406090204-FQI-045.TOT 04-FIC-045 00060Y000878279.312500G
DCS120170406090204-FQI-046.TOT 04-FIC-046 00060Y000815050.562500G
http://regexr.com/3g0d5
You probably want a non-capturing group:
^(?:.{4})([2-9][0-9]{3}[0-1][0-9][0-9]{2})(?:.*)$
(mouse over the text at: http://regexr.com/3g0db and it will show just one group)
I don't know C#, but from my Perl perspective, I don't see any need for a regular expression. If you just want "the date" and don't need to validate it or separate it into components, just get the substring starting at position 4 (0 based) and 8 characters long.

Exclude match in Regular Expression c# [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 6 years ago.
Improve this question
I would like to exclude a specific string when it is contained in an expression:
Example:
myurl.htm = exclude
myurl = include
I tried this one : ([a-z0-9]+)(?!.htm)
But looks like it doesn't work.
Try the following:
([a-z0-9]+)(?!^\.htm)
You had two errors in your expression:
You have to escape the dot . with a backslash because it means "matches any character (except newline)" unescaped.
You have to add a ^ to prevent cutting of the last character.
You can test your expression on this website: https://regex101.com/

Categories