This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
Closed 3 years ago.
I have a question with regex, I'm trying to scrape a stock price. The element surrounding it looks like this:
<span class="Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)" data-reactid="52">17.89</span>
As you see there are multiple parentheses in that element so when I try to narrow it down with the following code the parentheses cause my script not to display any results.
MatchCollection list = Regex.Matches(data, "<span class=\"Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)\" (.+?)</span>", RegexOptions.Singleline);
I Know you can ignore quotation marks using \ but is there away to ignore parentheses?
Double escape the parentheses solved it.
Related
This question already has answers here:
.NET Regex Error: [x-y] range in reverse order
(3 answers)
How to match hyphens with Regular Expression?
(6 answers)
Closed 4 years ago.
What I need is to check if a string only contains the characters > or < or -.
So I thought using a RegEx for this, and I found an SO question with the exact same problem, and it has an answer (not the accepted one but the answer with regex)
This is the SO question : String contains only a given set of characters
So I modified the expression in this question to fit my needs like this :
static readonly Regex Validator = new Regex(#"^[><- ]+$");
and I call it like this ;
Validator.IsMatch(testValue)
But it's throwing the error
x-y range in reverse order
There are lots of question on SO about this error but I cant find or understand the answer I need.
So what am I doing wrong with this RegEx?
^[-<>]+$ "-" must come first in C# regex
Escape - within character groups. ([0-9] means "zero to nine" and not "zero, dash or nine")
This question already has answers here:
Regular Expression Except this Characters
(4 answers)
C# Regular Expressions, string between single quotes
(4 answers)
Closed 5 years ago.
How do I match anything between single quotes? I need to match all attribute = 'some value' statements within a WHERE clause of queries. I tried:
= '(.+)'
But that doesn't work: somehow messes up all single quotes and matches.
If anyone could help me out it'd be much appreciated!
Try:
= '([^']*)'
Meaning you want anything/everything from = ' that isn't a single quote up to a single quote.
Python example:
import re
text = "attribute = 'some value'"
match = re.search("= '([^']*)'", text)
print(match.group(1))
To read more about that, it is called a negated character class: https://www.regular-expressions.info/charclass.html
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:
How do I match an entire string with a regex?
(8 answers)
Closed 6 years ago.
I need to detect following format when I enter serial number like
CK123456.789
I used Regex with pattern of
^(CV[0-9]{6}\.[0-9]{3}
to match but if I enter
CK123456.7890
it still able to proceed without flagging error. Is there a better regular expression to detect the trailing 3 digits after '.'?
Depending on how you use the regular expression matcher, you might need to enclose it in ^...$ which forces the pattern to be the whole string, i.e.
^CK[0-9]{6}\.[0-9]{3}$ (Note the CK prefix).
I've also removed your leading (mismatched) parenthesis.
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 6 years ago.
I am new to regex. What does regex expression match pattern "\[.*\]" mean?
If I have a text like "Hello [Here]", then success is returned in the match. And match contain [Here].
I read that:
. indicates Any except \n (newline),
* indicates 0 or more times
I don't understand the "\". It believe it is just escape sequence for "\".
So, is the expression "\[.*\]" trying to match a pattern like \[Any text\]?
Yes, you are right. It will match any characters enclosed in []. The .* imply any or no characters enclosed in [].
Also you should try this link which is a very helpful regex tool. You can input the regex pattern and check for matches easily.
I have tried this on regexr, here is a screen shot: