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 1 year ago.
Improve this question
I have a string that I want to remove some characters from
I want all % symbols and the character directly following that character to be removed
e.g. Apple%j pie turns into Apple pie
I want it to do this several times too, so Chicken%f and%f waffles turns into Chicken and waffles
Use regex matching a percent sign then any character:
var result = Regex.Replace("Chicken%f and%f waffles", #"%.", "");
//Chicken and waffles
Related
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.
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/
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 7 years ago.
Improve this question
Example Word : String , the returned last index is 5 which is "g". I need to complete the word string base on the space before the word.
For example
obj string the last index is 5, which is g, "string" word should be completed.
If you are using C#, you can use String.LastIndexOf method to report the last occurrence of ' ' character then use String.Substring to extract the word.
For other languages, Google is your friend :)
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"
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 2 years ago.
Improve this question
I have searched the site for this simple problem but cant find an answer.
I have a multiline string . I want to add a constant string to end of each line.
I am using Regex.Replace but facing problems. I tried to replace as the following.
Pattern Replace With
-------------------------------------------
$ Text
($) Text$1
\n Text
\n Text\n
(\n) Text$1
But none of these work. In all the cases the multiple lines are joined into a single line.
How can I accomplish this ?
You should be able to do:
string newString = oldString.Replace("\r\n", "Text\r\n");
replace Text with the string you want to append to the end of each line