Use RegEx to find 100$ in text c# [duplicate] - c#

This question already has answers here:
C# Regex Match whole word, with special characters
(2 answers)
Regex whitespace word boundary
(3 answers)
Closed 4 years ago.
I am trying to search 100$ through the RegEx. But unable to find its pattern is as above.
\b100\$\b
However, if the text contains 100$1 then it displays properly.
But I want to do exact search.

Word boundaries only work with word characters, not $. Try using this regex:
\b100\$(?=\s|\$)
This will match 100$, where what follows the $ is either whitespace or the end of the line.
Demo

Related

C# - The unicode regular expression to remove emoticons also remove another chars [duplicate]

This question already has answers here:
Detecting *all* emojis
(4 answers)
Unicode character range not being consumed by Regex
(3 answers)
Closed 3 years ago.
I'm using this statement to remove emoticons from a string:
text = Regex.Replace(text, #"[^\u1F600-\u1F64F]+", ""); //Emoticons
Based on the official Unicode page chart, https://www.unicode.org/charts/PDF/U1F600.pdf.
But this replace statement not only remove emoticons also removes another characters like "." or "-".
Why is that?

Why does regex detect newline as a valid newline but not \n? [duplicate]

This question already has answers here:
Regex that matches a newline (\n) in C#
(5 answers)
Closed 3 years ago.
I'm currently trying to test out a regex for a project I'm working on, I've found a problem while doing it. (these are C# regexes from System.Text.RegularExpression)
The input:
11
w
Pattern 1:
\d{1,}
\w
Pattern 2:
\d{1,}\n\w
in this page that I found, it states that \n matches a new line character (and in any other page I could looked at)
so if that's the case, why does pattern 1 match the input but pattern 2 not? shouldn't they be the same?
from what Tim Biegeleisen said, "on windows the line separator is not just \n, it's \r\n", with this I changed pattern 2 to \d{1,}\r\n\w and everything turned out fine.

Match everything between characters in Regex? [duplicate]

This question already has answers here:
How do I match any character across multiple lines in a regular expression?
(26 answers)
Closed 3 years ago.
I am trying to match everything between
/* and */
And also include the in between characters.
I currently managed to create a pattern that kind of does this
\/\*(.+?)\*\/
Regex Tester
But it doesn't match multi line quotes and only matches once.
How can I improve this pattern to match everything that starts with /* and ends with */ ?
You need the RegexOptions.Singleline option, which makes the . match newlines.
Regex rx = new Regex("/\*(.+?)\*/", RegexOptions.Singleline);

How to get all possible Regex Matches [duplicate]

This question already has answers here:
C# Code to generate strings that match a regex [closed]
(4 answers)
Closed 3 years ago.
Based off a regex string I would like to get a list of all the possible strings that would match the regex.
Example:
Given a regex string like...
^(en/|)resources/case(-| )studies/
I want to get a list of all the possible strings that would match the regex expression. Like...
^en/resources/case-studies/
or
^/resources/case-studies/
or
^en/resources/case studies/
or
^/resources/case studies/
Thank you
Note that in regex ^ denotes the beginning of the line. You must escape it
Try
\^(en)?/resources/case(-|\s)studies/
explanation:
\^ is ^ escaped.
(en)? is optionally en, where ? means zero or one times.
/resources/case the text as is.
(-|\s) minus sign or white space.
studies/ the text as is.
See: https://dotnetfiddle.net/PO4wKV

Regex expression to verify that a string only contains letters, numbers, underscores and dashes [duplicate]

This question already has answers here:
Reference - What does this regex mean?
(1 answer)
What do ^ and $ mean in a regular expression?
(2 answers)
Closed 3 years ago.
I've already read this here and I still have got some questions. I will be very grateful if you can help me to solve them. I'm trying to compose a RegEx to verify that a string contains only letters, numbers, underscores and hyphens. Firstly, when I tried to do it (without Google-search) I did this #"[A-Za-z0-9_-]". After I made some research I found that it should be #"^[a-zA-Z0-9_-]$" where:
^ asserts position at start of a line
$ asserts position at the end of a line
My question is why we should insert these symbols? And my other question is why the string "jeffbutt" (with yellow in the screenshot) doesn't match?

Categories