I need to extract the value of studentId just 1413 how could this be done?
All this code below is stored in a single variable I think with regex it is possible but had no luck with it

$(document).ready(function () {
        var getSchedule = function () {
            $.ajax({
                type: 'GET',
                url: "Schedule",
                data: {
                    "studentId": 1413,
                    "term": $("#Term").val(),
                    "academicYear": ,
                    "docId": $("#DocId").val()
                },
                beforeSend: function () {
                    $('#contentArea').html('<center><img src="../../Content/images/ajax-loader.gif" alt="loading"/></center>');
                },
                success: function (data) {
                    $("#contentArea").html(data);
                },
                dataType: "html",
                error: function () {
                    alert("Error");
                }
            });
        }

In PHP you would use $_GET['studentId']

no this data is in a variable so it is one long string i think i need some sort of preg_match but i can't seem to find the right combination of symbols

Member Avatar

Your comment and code do not make any sense.

I need to extract the value of studentId just 1413 how could this be done?

Then

data: {
    "studentId": 1413,
    "term": $("#Term").val(),
    "academicYear": ,
    "docId": $("#DocId").val()
},

So first idea is that you want to pick up $_GET['studentId'], but then you say...

no this data is in a variable so it is one long string i think i need some sort of preg_match but i can't seem to find the right combination of symbols

Why didn't you just post the long string and tell us which bits of data you need to extract? Posting the ajax code was unnecessary, if I'm understanding you correctly.

That code is what is in the string. the data i need to extract is the value 1413

Member Avatar

So the code posted is the string. Ok got it now.

preg_match('/"studentId": (\d+)/', $str, $matches);
echo $matches[1];

Maybe

I'm real curious on how you are storing that in a string. You have a mixture of double and single quotes in it. Are you escaping everything? diafol's regex would work but there is something that we are not seeing here.