RegEx...Trying to replace pattern in Html file [duplicate] - c#

This question already has answers here:
Regular expression for floating point numbers
(20 answers)
Closed 3 years ago.
I want to replace the following pattern in an html file
<BR>1696.54</TD>
to
<TD>1696.54</TD>
I am using the RegEx.Replace code
result = Regex.Replace(html, "<BR>\d</TD>", "<TD>$1</TD>")
but I am doing something incorrectly as nothing happens.
Any help would be appreciated..

You need capture a group using parentheses and change :
`\d`
to
`\d*\.\d*`
try this :
result = Regex.Replace(html, "<BR>(\d*\.\d*)</TD>", "<TD>$1</TD>")

Related

c# shorten path "C:\Users\me\..\you" to "C:\Users\you" [duplicate]

This question already has answers here:
Remove dots from the path in .NET
(10 answers)
Closed 1 year ago.
Is there a built in way of removing unnessacary statements like this \hello\.. from a path in C# or do I have to do this using regex replace?
Example:
C:\Users\me\myfolder\..\anotherFolder\image.png to C:\Users\me\anotherFolder\image.png
C:\Users\me\myfolder\..\..\you\f\image.png to C:\Users\you\f\image.png
my solution using regex would be removing this /\\([^\.\\]+)\\\.\./ using a loop regexr.com
You should just be able to write this:
string fixedPath = Path.GetFullPath(#"C:\Users\me\myfolder\..\anotherFolder\image.png"));
Result in fixedPath:
C:\Users\me\anotherFolder\image.png

How to build a string regex pattern for number range from 0000-4095 [duplicate]

This question already has answers here:
Using regular expressions to validate a numeric range
(11 answers)
Closed 3 years ago.
I want to build a regex to search number in a string (using c#) with range from 0000-4095. I use this string pattern:
string regex_pattern = (0?[0-3][0-9][0-9][0-9]|{4}{0}[0-9]{0}|{4}{0}{9}[0-5]);
But i can not get success.
Can you please show me some hints?
Thanks
You could use
^([0123][0-9][0-9][0-9]|40[0-8][0-9]|409[0-5])$
Regex Demo
Sample
sorry for the multiples groups:
([0-4]0(([0-9][0-5])|([0-8][0-9])))|([0-3][0-9]{3})
Sample

fetch sub-string using regex [duplicate]

This question already has answers here:
Regular expression to extract text between square brackets
(15 answers)
Closed 5 years ago.
string subject = "Re: Customer request [#11#]";
I want to fetch [#11#] from the above string. At run time instead of 11 there can be any number e.g. 12,13,14 etc.
Please suggest me appropriate Regex to fetch this output.
Something like this: \[#\d{0,}#\]
You can fiddle with it on https://regex101.com/r/uA8fX9/3

C# Regular Expression - find groups in text with a separator [duplicate]

This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 6 years ago.
I have the following text
"a|mother" "b|father"
I want to find via Regex, groups of text that starts with '"' and ends with '"' and separate with '|' without spaces. Meaning the results would be:
"a|mother"
"b|father"
I try to use other posts to solve my question but still with no luck how can I find the |? and how can I find my pattern without spaces?
Something like this:
String source = "\"a|mother\" \"b|father\"";
var result = Regex
.Matches(source, "\"[^\"]*[^ ]\\|[^ ][^\"]*\"")
.OfType<Match>();
Console.Write(String.Join(Environment.NewLine, result));
Output is
"a|mother"
"b|father"

Regular Expression that matches any .aspx url [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 7 years ago.
The text I was going through mentioned that following regular Expression matches any .aspx url:
#"?i:^.*\.aspx.*$"
I couldnot understand what ?i:^ did while matching. Pls. explain what part it matches in urls like http://localhost:2447/Out.aspx, https://msdn.microsoft.com/en-us/library/88c54tsw.aspx.
?i means ignore case. Your pattern also has some unneeded fillers. If you only want to check if the string contains .aspx, use this:
(?i)\.aspx
// Match:
http://localhost:2447/Out.aspx
http://localhost:2447/Out.AsPx/suburl
https://msdn.microsoft.com/en-us/library/88c54tsw.aspx

Categories