Reputation:
I currently have a reg ex that reads in just the score of the home and away team and only registers taking numbers. I want to accept null values however, to store fixtures.
Im not certain which flavor of regex im using, but for sure it isn't PCRE. Apologies for the lack of information, its been a while since i touched this Regex specific pattern.
private static final Pattern FIXTURES_REGEX = Pattern.compile("\\{\"fixture_id\".*?\"homeTeam_id\":\"?(\\d+)\"?,\"awayTeam_id\":\"?(\\d+)\"?,.*?\"goalsHomeTeam\":\"?(\\d+)\"?,\"goalsAwayTeam\":\"?(\\d+)\"?,.*?\"firstHalfStart\":\"?(\\d+)\"?");
This is the regex im currently working with, but to relate to exactly what i need to change, is the phrase:
.*?\"goalsHomeTeam\":\"?(\\d+)\"?
Which only selects numbers from this value. I then pass this regex through a matcher and use a loop to .find the correct values.
An example of the data i would be reading is:
"goalsHomeTeam":"2"
Or
"goalsHomeTeam":NULL
Many thanks, Luke
Upvotes: 0
Views: 17749
Reputation: 1883
Regex for expression containing NULL or Number
^[0-9]*$|^NULL$
If instead of NULL you consider blank string then:
^[0-9]*$|^\w$
Upvotes: 1