This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
RegEx match open tags except XHTML self-contained tags
I need it
How can i get "I need it" sentence? I want use regular expression...
Here's the regex pattern that you can use to extract what you want:
(?<=\<a\shref=.*?\>).*?(?=\<\/a\>)
Related
This question already has answers here:
My regex is matching too much. How do I make it stop? [duplicate]
(5 answers)
Closed 4 years ago.
I am trying to get my regex expression to work to no avail:
All I want to do is find the image tags in an html string so I can replace them:
This is what I think should work:
var regex = new Regex(#"<img.*>");
return regex.Replace(content, "<p><i><b>(See Image Online)</b></i></p>");
And it does work partially, but it seems to be stripping out more than just the image tag.
This is an example of what I want to match:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAM0AAAD
NCAMAAAAsYgRbAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5c
cllPAAAABJQTFRF3NSmzMewPxIG//ncJEJsldTou1jHgAAAARBJREFUeNrs2EEK
gCAQBVDLuv+V20dENbMY831wKz4Y/VHb/5RGQ0NDQ0NDQ0NDQ0NDQ0NDQ
0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0PzMWtyaGhoaGhoaGhoaGhoaGhoxtb0QGho
aGhoaGhoaGhoaGhoaMbRLEvv50VTQ9OTQ5OpyZ01GpM2g0bfmDQaL7S+ofFC6x
v3ZpxJiywakzbvd9r3RWPS9I2+MWk0+kbf0Hih9Y17U0nTHibrDDQ0NDQ0NDQ0
NDQ0NDQ0NTXbRSL/AK72o6GhoaGhoRlL8951vwsNDQ0NDQ1NDc0WyHtDTEhD
Q0NDQ0NTS5MdGhoaGhoaGhoaGhoaGhoaGhoaGhoaGposzSHAAErMwwQ2HwRQ
AAAAAElFTkSuQmCC" alt="beastie.png">
You need either
new Regex(#"<img.*?>");
if supported, or if not,
new Regex(#"<img[^>]*>");
Your problem is that your regular expression is not matching the first ">" it finds but LAST.
This question already has answers here:
Returning only part of match from Regular Expression
(4 answers)
Closed 4 years ago.
I have a responce string
"c=2020&action=approvecomment&_wpnonce=7508ac918a' data-wp-lists='dim:the-comment-list:comment-2020:unapproved:e7e7d3:e7e7d3:new=approved"
Im trying to extract 2020 and 7508ac918a. I dont understand how I must use regex with substrings in C#, simple regex like
c=(\d+)&action=approvecomment&_wpnonce=(.*?)' .+new=approved.
In Regex, you can create match groups
They look like this (?.+?)
So your _wpconce part could become something like this (?.*?)
Then you can grab each group individually for example
Match result = myRegex.Match(someString);
soneOtherString = result.Groups["GROUPNAME"].Value;
I use Regex101 to build and test my regex. (Whoever made that site deserves a crown with shinny stones on it!! :)
https://regex101.com/
Hope this helps
This question already has answers here:
How to use string.Endswith to test for multiple endings?
(9 answers)
Closed 5 years ago.
I need to check if a string last word is either "...abc" or "...xyz" or "...fgh".
How i can achieve the same thing using regex as i am trying to learn it?
e.g Sentence 1: Hi My Name is abc.
Sentence 2: I live in xyz.
The above sentence is a sample one to demonstrate.
You don't need any Regex. Just use String.EndsWith :
string a = "asdasd abc";
Console.WriteLine(a.EndsWith("abc.") || a.EndsWith("xyz.") || a.EndsWith("fgh."));
You can use this simple regex pattern:
(abc|xyz|fgh)$
Put your possible options between parenthesis separated by pipes. The $ means the end of the string.
This question already has answers here:
Capturing parts of string using regular expression in R
(3 answers)
Closed 5 years ago.
I need to parse a text file for certain information. I am using a regular expression to do so. My question is, is it possible to match an expression but only capture a relevant part, negating the need to strip the unnecessary characters after capture?
Of course, google "regex capturing groups" or check this link: https://msdn.microsoft.com/en-us/library/bs2twtah(v=vs.110).aspx#named_matched_subexpression
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What is the best regular expression generator/explainer
Is there a way to go from a regular expression to what does it mean?
for example I found the following expression in an old code:
.*[^a-zA-Z0-9_].*
...but I do not know if this is 100% correct or if it contains any unnecessary characters?
Is there any online tool that does regular expression translation?
I use http://gskinner.com/RegExr/. You can enter both the Regex and the text you want to apply it to. It also contains a couple of samples.