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
I am trying to match a string containing nothing before a character.
Consider the following lines:
'this is a valid line
'this is also a valid line
Any string ' this is an invalid line
I Need a regular expression that matches the first two line and does not match third line.
Basic regex tried was '.* but it matches all the three lines:
So need a regex that does not match a non empty string before '
perhaps try anchor at the beginning... ^\s*'.*
Related
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 3 years ago.
Improve this question
I have to check if string contains only lowercase letters, from 'd' onwards, and the symbols '{', '}', '|', '#'.
I have tried to create Regex but it matches substrings which is not the desired behaviour (the second test mustn't match in the example which I add). I don't know how to explain that the order isn't important and the strings must contain only of the allowed characters. Regex101
[d-z]+[{}|#]+
This regex matches arx#vkdww#qrw#sdvv and this isn't right. How can I fix it?
Thank you in advance!
Your pattern [d-z]+[{}|#]+ matches 1+ times a char d-z in a character class followed by one of the chars listed in the character class [{}|#]+
You have to use anchors to assert the start ^ and end $ of the string and use 1 character class containing all the allowed characters instead of 2:
^[d-z{}|#]*$
Regex demo
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 C# code to replace hashtags in HTML strings and it works good but it also replaces apostrophes since they encode as '
The code replaces the #39 with the URL.
Such as Hamburger's is now converted to Hamburger&<a href\"Default.aspx?search=39">39</a>s
How can I ignore apostrophes for the regex replace?
public String ReplaceHashTags(string strContent)
{
string strHashtags = #"#(\w+)";
strContent = Regex.Replace(strContent, strHashtags,
"$1");
return strContent;
}
You can tell the Regex to not match if the # is preceded by &:
var strHashtagPattern = #"(?<!&)#(\w+)";
If you want to exclude all possible special character escapes, a negative lookahead may be better:
var strHashtagPattern = #"(?!(?<=&)#[\w\d]+;)#(\w+)";
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 .*.
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)
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