Rectangle 27 2

First, I would recommend Expresso. It is free, but you do have to register it. I find it very valuable both for working with regular expressions as well as learning to use them better. One final warning is that string parsing with regex (especially web page content; which is what yours appears to be), is especially brittle and can easily break. A regular expression that works right now, can easily start failing if the text has small changes.

With that out of the way, now for your specific question. I am assuming the result set that you are looking for is 0,13,135,171,1148,732,10 (all of the competion ids)

We will start by opening Expresso and pasting all of the text into the Sample Text (bottom left) area (make sure you are on the Test Mode tab). Now we will start writing a regular expression to find the text we are looking for. Put competition_id": into the Regular Expression area (top left). If you expand out the tree in the Regex Analyzer (top right), it will show each of the individual characters. This indicates that all of these characters will be matched literally. If you click the Run Match button, you will see a list of matches displayed in the Search Results (bottom right). Perfect, it found all 8 areas where that text appears. You can click on each of the Search Results and Expresso will highlight the corresponding area in the Sample Text. Now we need to expand this to match the number after it. If you click on the Design Mode tab you will see an area at the bottom that lists all of the regular expression symbols and what they mean. I find this area helpful for looing up various matching patterns. Change the regular expression to be competition_id":\d+

The \d means match any digit (0-9) and the + means match one or more of them. If you click Run Match you will see that each of the matches now contains the text competition_id:"<number>

If we use this regular expression in C#, it will return back all of the text, and in this case we just want the number. One final change to the regex competition_id":(\d+). Note that in the Regex Analyzer it now indicates that we have a number capture group. All this means is that portion of the match that is inside of the parenthesis will be put into its own group that we can easily extract. Click Run Match, and you will notice that the matches still contain the full text match, but now there is a sub group under each that contains the individual value.

Now back in C#, I will assume that you you that large script block in a string value named data.

string data = ...;
//Get all of the matches
MatchCollection matches = Regex.Matches(data, "competition_id\":(\\d+)");
foreach (Match match in matches)
{
    //This is the group number that we saw in expression. Group[0] will be the full match.
    Group group = match.Groups[1]; 
    //Get the value out of the group. We can do an int.Parse since we know it will only contian digits
    int competition_id = int.Parse(group.Value);
    //TODO: Do something with competition_id
}

Note: We do have to escape the regular expression when it is represented as a string.

This is only a small introduction into regular expressions. I would encourage you to play around with Expresso and poke around online. There are lots of good resources out there. The most important thing to do is practice.

hi, thanks for the amazing answer, unforunately I get matches.Count = 0; the content of data is this: pastebin.com/AS7vMBYq

Sorry had a small typo when I moved the regular expression patter into the C#. I accidently put a space between the \d and the +. This causes the regular expression to fail because the + only affects the thing directly before it (which was the space and not the \d as intended. The updated code should work.

Another option is using HTMLAgilityPack and (Jurassic library or XPath) to get what you want.

javascript - How to get js code from regex? - Stack Overflow

javascript c# html regex
Rectangle 27 1

First, I would recommend Expresso. It is free, but you do have to register it. I find it very valuable both for working with regular expressions as well as learning to use them better. One final warning is that string parsing with regex (especially web page content; which is what yours appears to be), is especially brittle and can easily break. A regular expression that works right now, can easily start failing if the text has small changes.

With that out of the way, now for your specific question. I am assuming the result set that you are looking for is 0,13,135,171,1148,732,10 (all of the competion ids)

We will start by opening Expresso and pasting all of the text into the Sample Text (bottom left) area (make sure you are on the Test Mode tab). Now we will start writing a regular expression to find the text we are looking for. Put competition_id": into the Regular Expression area (top left). If you expand out the tree in the Regex Analyzer (top right), it will show each of the individual characters. This indicates that all of these characters will be matched literally. If you click the Run Match button, you will see a list of matches displayed in the Search Results (bottom right). Perfect, it found all 8 areas where that text appears. You can click on each of the Search Results and Expresso will highlight the corresponding area in the Sample Text. Now we need to expand this to match the number after it. If you click on the Design Mode tab you will see an area at the bottom that lists all of the regular expression symbols and what they mean. I find this area helpful for looing up various matching patterns. Change the regular expression to be competition_id":\d+

The \d means match any digit (0-9) and the + means match one or more of them. If you click Run Match you will see that each of the matches now contains the text competition_id:"<number>

If we use this regular expression in C#, it will return back all of the text, and in this case we just want the number. One final change to the regex competition_id":(\d+). Note that in the Regex Analyzer it now indicates that we have a number capture group. All this means is that portion of the match that is inside of the parenthesis will be put into its own group that we can easily extract. Click Run Match, and you will notice that the matches still contain the full text match, but now there is a sub group under each that contains the individual value.

Now back in C#, I will assume that you you that large script block in a string value named data.

string data = ...;
//Get all of the matches
MatchCollection matches = Regex.Matches(data, "competition_id\":(\\d+)");
foreach (Match match in matches)
{
    //This is the group number that we saw in expression. Group[0] will be the full match.
    Group group = match.Groups[1]; 
    //Get the value out of the group. We can do an int.Parse since we know it will only contian digits
    int competition_id = int.Parse(group.Value);
    //TODO: Do something with competition_id
}

Note: We do have to escape the regular expression when it is represented as a string.

This is only a small introduction into regular expressions. I would encourage you to play around with Expresso and poke around online. There are lots of good resources out there. The most important thing to do is practice.

hi, thanks for the amazing answer, unforunately I get matches.Count = 0; the content of data is this: pastebin.com/AS7vMBYq

Sorry had a small typo when I moved the regular expression patter into the C#. I accidently put a space between the \d and the +. This causes the regular expression to fail because the + only affects the thing directly before it (which was the space and not the \d as intended. The updated code should work.

javascript - How to get js code from regex? - Stack Overflow

javascript c# html regex
Rectangle 27 1

For those that are on OSX and want to use Python, but not loose the XML formatting which when parsing is done by the python XML parser happens, here is a python script that will do the incremental based on regular expression, which keeps the formatting:

#!/usr/bin/python
import re

f = open('AndroidManifest.xml', 'r+')
text = f.read()

result = re.search(r'(?P<groupA>android:versionName=")(?P<version>.*)(?P<groupB>")',text)
version = str(float(result.group("version")) + 0.01)
newVersionString = result.group("groupA") + version + result.group("groupB")
newText = re.sub(r'android:versionName=".*"', newVersionString, text);
f.seek(0)
f.write(newText)
f.truncate()
f.close()

The code was based on @ckozl answer, just was done in python so you don't need to create an executable for this. Just name the script autoincrement.py, place it in the same folder with the manifest.xml file and then do the steps that ckozl did describe above!

eclipse - Auto increment version code in Android app - Stack Overflow

android eclipse build version
Rectangle 27 0

You can't parse XML with regex. Because XML can't be parsed by regex. Regex is not a tool that can be used to correctly parse XML. As I have answered in XML-and-regex questions here so many times before, the use of regex will not allow you to consume XML. Regular expressions are a tool that is insufficiently sophisticated to understand the constructs employed by XML. XML is not a regular language and hence cannot be parsed by regular expressions. Regex queries are not equipped to break down XML into its meaningful parts. so many times but it is not getting to me. Even enhanced irregular regular expressions as used by Perl are not up to the task of parsing XML. You will never make me crack. XML is a language of sufficient complexity that it cannot be parsed by regular expressions. Even Jon Skeet cannot parse XML using regular expressions. Every time you attempt to parse XML with regular expressions, the unholy child weeps the blood of virgins, and Russian hackers pwn your webapp. Parsing XML with regex summons tainted souls into the realm of the living. XML and regex go together like love, marriage, and ritual infanticide. The <center> cannot hold it is too late. The force of regex and XML together in the same conceptual space will destroy your mind like so much watery putty. If you parse XML with regex you are giving in to Them and their blasphemous ways which doom us all to inhuman toil for the One whose Name cannot be expressed in the Basic Multilingual Plane, he comes. XML-plus-regexp will liquify the nerves of the sentient whilst you observe, your psyche withering in the onslaught of horror. Regex-based XML parsers are the cancer that is killing StackOverflow it is too late it is too late we cannot be saved the trangession of a child ensures regex will consume all living tissue (except for XML which it cannot, as previously prophesied) dear lord help us how can anyone survive this scourge using regex to parse XML has doomed humanity to an eternity of dread torture and security holes using regex as a tool to process XML establishes a breach between this world and the dread realm of corrupt entities (like SGML entities, but more corrupt) a mere glimpse of the world of regex parsers for XML will instantly transport a programmer's consciousness into a world of ceaseless screaming, he comes, the pestilent slithy regex-infection will devour your HTML parser, application and existence for all time like Visual Basic only worse he comes he comes do not fight he comes, his unholy radiac destroying all enlightenment, XML tags leaking frm your eyes like liquid pain, the song of regular expression parsing will extinguish the voices of mortal man from the sphere I can see it can you see it it is beautiful the final snuffing of the lies of Man ALL IS LOST ALL IS LOST the pony he comes he comes he comes the ichor permeates all MY FACE MY FACE h god no NO NOOOO N stop the an*gles are not real ZALG IS TO THE PONY HE COMES

text-processing command-line awk sed grep
Rectangle 27 0

It is a bad idea to use regular expressions for this kind of parsing. Use an XML parser for this particular scenario. I suggest LINQ to XML, i.e. XElement.Parse(...)

Do not forget to wrap you html in a single root element though.

This is not true! It is perfectly reasonable to use regexes on small bits of captive tame X/HTML like this. Its far more reasonable that the alternative, which has about a 10,000:1 blowup and is fiddly to boot. This is the perfect situation for applying regexes to X/HTML.

regex - What is wrong with my regular expression? - Stack Overflow

regex c#-4.0