0

This is driving me nuts, but I can't make this very simple regular expression work. I have a JSON object, and I am trying to sum all of the properties that start with "eehrs_" (the values for these properties are all integers). Just to debug it, I am trying to simply print out the property name to show that the loop is working. Here is the regular expression and loop I am using. Any help would be greatly appreciated:

for (i = 0; i < schoolJSON.features.length; i++) {
    for (property in schoolJSON.features[i].properties) {
        if (property == /(eehrs_\d+)|(eehrs_[p|k])/) { 
            console.log(property);
        }
    }
}

Also, I tried using a simple /^eehrs_/, but that did not work either.

Thanks, Jon

1

1 Answer 1

2

You're doing it wrong:

if (/^eehrs_(?:\d+|[pk])/.test(property)) {
    ...

You don't have to test if a string is a regular expression, but rather you use the regex to test the string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.