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
Related
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>")
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
Is there a way to verify with Regex that a string matches a patter like so:
1.001
1.002
15.001
Where the pattern is:
any number followed by
dot character
followed by three (3) numbers
Given that patters things like this would fail:
A.001
1.0001
1,001
...
Any help is appreciated.
This regex should work:
^\d+\.\d{3}$
This question already has answers here:
How do I match any character across multiple lines in a regular expression?
(26 answers)
Closed 6 years ago.
Issue
I am having an issue creating a regex to accept any string and the ENTER key, at the moment i have this:
^$|^.+$
I have looked around and people have said to add \n but this does not work.
An example of the string is should allow is as follows:
Hello this is a test string
and i want this to be accepted
Try setting the s flag on the regex engine. This will ensure that the . metacharacter will match newlines.
Here's a link to a working example.
Also, as a sidenote, instead of ^$|^.+$ you can condense the whole expression to ^.*$ to achieve the same results with better performance.
In C#, you need the RegexOptions.Singleline option. See this SO post for more information.
Here is a quick example that really just matches the entire string, so it's not useful.
var regex = new Regex(#"^.*$",
RegexOptions.IgnoreCase | RegexOptions.Singleline);
In your future validation code, you need to replace .* with whatever your validation will be.
This question already has answers here:
Regular expression to match a line that doesn't contain a word
(34 answers)
Closed 8 years ago.
Say I have the following string:
test tester tested testing
I wish to match every word that begins with test, but not the word tester. The pattern test\w* does most of the job, but I have no idea how to add that tester should not be matched. A working pattern should give 3 matches on the string.
Does this work for your purposes?
test(?!er).*
This question already has answers here:
What is the best regular expression to check if a string is a valid URL?
(62 answers)
I need a regEx to match general URLs
(3 answers)
Closed 9 years ago.
I need a Regex validating Url:
This should be valid
http://www.google.com
https://www.google.com
but not this:
google.com
www.google.com
I know this can be done with Uri.IsWellFormedUriString for example but I need a regex. Found a couple of similar topics but does not fit my case.Thanks!
Are you sure you want regex and not this - Uri.TryCreate?
Also have you gone through this post - What is the best regular expression to check if a string is a valid URL?
(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,#?^=%&:/~\+#]*[\w\-\#?^=%&/~\+#])?
try this
Regex urlchk = new Regex(#"((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)+(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,15})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9\&%_\./-~-]*)?", RegexOptions.Singleline | RegexOptions.IgnoreCase);