Reputation: 1369
here is a program to match a regular expression
string="Mozilla/5.0 (Series40; NOKIA311/03.81; Profile/MIDP-2.1 Configuration/CLDC-1.1) Gecko/20100401 S40OviBrowser/2.2.0.0.31";
regex=/(nokia).*([a-zA-Z0-9]+)/i
regex.exec(string)
My problem is its not matching to NOKIA and 311
Could anyone help.please
Upvotes: 0
Views: 1132
Reputation: 191799
The problem is the .*
, which tries to match as much as possible. It actually ends up matching the entire rest of the string and only leaves the 1
from the very end to satisfy the [a-zA-Z0-9]+
. You need a more specific regex, perhaps:
/nokia(\d+)/i
/nokia(.*?)\//i
The .*?
makes the .*
reluctant, so it will only match up to the first slash.
Upvotes: 2
Reputation: 2139
use the regex /NOKIA([\d\w]*)/i
Which will match the pattern NOKIA and any number or word without spaces
Upvotes: 0