Regex to get last 4 characters before first occurrence of "/" [closed] - c#

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Below are the test input . The result I want is AAA- and AB-- respectively. The input string has no specific pattern. So first occurrence of / and the 4 character before that is the result I want to have.
Test line abc (r);AAA-/2010/001
Test line abc (r);AB--/2010/001

Like that? (EDIT: in .NET regex patterns, / does not need escaping)
(.{4})/
Consider sites like https://regex101.com for future needs)

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 to remove c# [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I want to remove some string from regex in c#.
I have a string
000603ABC140702-005051-I-FILL200-NNYYNY180319-142110-A2002.zip
From this I want to remove those strings
140702
142110
And I want a result as
000603ABC-005051-I-FILL200-NNYYNY180319--A2002.zip
How can I do that in regex?
You can use the Regex.Replace method (https://msdn.microsoft.com/en-us/library/xwewhkd1(v=vs.110).aspx).
var regex = new Regex("(140702)|(142110)");
var result = regex.Replace("000603ABC140702-005051-I-FILL200-NNYYNY180319-142110-A2002.zip", "");
Although, as already stated by #CompuChip, String.Replace would probably be more efficient in this case. There's a discussion of various methods of replacing substrings and their efficiency at https://blogs.msdn.microsoft.com/debuggingtoolbox/2008/04/02/comparing-regex-replace-string-replace-and-stringbuilder-replace-which-has-better-performance/.

How to find __tokens__ in a string without using RegEx in C# [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have the following:
The __animal__ jumped over the __object__
I'd like to write a concise method in C# that returns animal and object. How can this be done without RegEx? A dirty solution would be to iterate through the characters one by one until we find a __ and then build a string until we find the closing __ - but I'm looking for a more elegant approach.
You are going to have to iterate in some form - if you don't want to use regex.
string text = "The __animal__ jumped over the __object__";
List<string> words = text.Split(' ').ToList();
words = words.Where(x => x.StartsWith("__") && x.EndsWith("__")).ToList();
You can use extensions of IEnumerable.to search, like above. but the framework is technically iterating.

What regex pattern can I use to match this string? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
What regex pattern can I use to match the following:
Dxx-xxxx/xxx
So:
- Any string that starts with character 'D'
- Has any number of any character between the 'D' and the '-'
- Has any number of any character between the '-' and the '/'
- Has any number of any character after the '/'
Apologies if I haven't explained this very well!
What is so difficult on D.*-.*/.*?
If you want to ensure that there is at least one character for behind the D, - and / respectivly you should use .+ instead of those .*.

RegEX : Find match based on condition [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am new to RegEx and looking for a solution to this condition. I am writing my code in C# and don't want to use any STRING functions.
Below is a sample string that I get:
610WBDFGFGM0122544
Now the condition I need to check is,
If string starts with "6" && 6th character is "D"
Can anyone tell me how to write RegEx for the above condition?
You can use this regex:
^6.{4}D
Here, ^ is the start of the string, .{4} means any four characters.
Online demo

Categories