I am trying to get values from the following text. How can this be done with Regex?
Lorem ipsum dolor sit %download%#456 amet, consectetur adipiscing %download%#3434 elit. Duis non nunc nec mauris feugiat porttitor. Sed tincidunt blandit dui a viverra%download%#298. Aenean dapibus nisl %download%#893434 id nibh auctor vel tempor velit blandit.
456 3434 298 893434
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.
Full form of C is “COMPILE”. One thing which was missing in C language was further added to C++ that is 'the concept of CLASSES'.
C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.
So you're trying to grab numeric values that are preceded by the token "%download%#"?
Try this pattern:
(?<=%download%#)\d+
That should work. I don't think #
or %
are special characters in .NET Regex, but you'll have to either escape the backslash like \\
or use a verbatim string for the whole pattern:
var regex = new Regex(@"(?<=%download%#)\d+"); return regex.Matches(strInput);
Tested here: http://rextester.com/BLYCC16700
NOTE: The lookbehind assertion (?<=...)
is important because you don't want to include %download%#
in your results, only the numbers after it. However, your example appears to require it before each string you want to capture. The lookbehind group will make sure it's there in the input string, but won't include it in the returned results. More on lookaround assertions here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With