Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Very simple REGEX problem

Need help with this string.

Pretty much I need to detect if this exact string exists, however the numbers can be anything.

How can i do this using regex? Thanks

PHP Code

<?php 
string PageEnd 
= "{\"total\":335,\"items\":[]}"; 

Below doesn't work... but it's what im trying to do

PHP Code

<?php 
Regex r 
= new Regex("{\"total\":" + @"^\d+$" + ",\"items\":[]}");
if (
r.Match(stringImComparing).Success)
{
//do stuff
} 

Current work-around:
PHP Code

<?php 
string PageEnd 
= "items\":[]}";
if (
ReturnedHTML.Contains(PageEnd))
{
// Console.WriteLine("Found End Page");
MaxPage = k;
} 
Code
Try
    If Regex.IsMatch( "{\""total\"":335,\""items\"":[]}", "\{\\""total\\"":[^]\n\r"",:[\\eimst}]{3},\\""items\\"":\[\]\}") Then
        ' Successful match
    Else
        ' Match attempt failed
    End If
Catch ex As ArgumentException
    'Syntax error in the regular expression
End Try
(Oct 29, 2016 05:45 PM)-SomE. Wrote:  
Code
Try
    If Regex.IsMatch( "{\""total\"":335,\""items\"":[]}", "\{\\""total\\"":[^]\n\r"",:[\\eimst}]{3},\\""items\\"":\[\]\}") Then
        ' Successful match
    Else
        ' Match attempt failed
    End If
Catch ex As ArgumentException
    'Syntax error in the regular expression
End Try

Thanks 👍
This isn't a task for regex mate, use a json deserializer to check or just use string#Contains to check if the two keys exists
JSON deserialization would be much better. Add a reference to System.Web.Extensions and then you can use the System.Web.Script.Serialization.JavaScriptSerializer class.
pcre php regex

Code
([{].{2}total.{2}[:]\d{3}.{3}items.{3}[[][]][}])

however i do suggest deserialization as well :)
(Oct 30, 2016 09:38 AM)Ninja Wrote:  JSON deserialization would be much better. Add a reference to System.Web.Extensions and then you can use the System.Web.Script.Serialization.JavaScriptSerializer class.

Sorry for the off-topic, but I have a question:

Are there any advantages referencing to System.Web.Extensions for using System.Web.Script.Serialization.JavaScriptSerializer instead adding a reference to System.Runtime.Serialization for using System.Runtime.Serialization.Json.DataContractJsonSerializer class?

Or maybe both classes 'do the same' job? (serialize/deserialize JSON data)

PS: I've always used DataContractJsonSerializer class for JSON stuff.
(Oct 30, 2016 10:10 AM)Zilog80 Wrote:  Sorry for the off-topic, but I have a question:

Are there any advantages referencing to System.Web.Extensions for using System.Web.Script.Serialization.JavaScriptSerializer instead adding a reference to System.Runtime.Serialization for using System.Runtime.Serialization.Json.DataContractJsonSerializer class?

Or maybe both classes 'do the same' job? (serialize/deserialize JSON data)

PS: I've always used DataContractJsonSerializer class for JSON stuff.

I haven't used the latter that much and I am more familiar with the first. As far as advantages go I have no clue.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by HardStoNMay 9, 2019 11:22 AM 2 91 May 9, 2019 11:22 AM
Last Post: HardStoN
[Python] by TheWarOwlAug 23, 2017 10:13 PM 2 121 Aug 23, 2017 10:13 PM
Last Post: TheWarOwl
[C#] by i3urnApr 12, 2017 11:03 AM 4 153 Apr 12, 2017 11:03 AM
Last Post: Owl