regex - Stop at first match when greedy matching -


i'm trying create mod_rewrite rule match first language accept-language header. header may contain 1 language code, contains more one. need match first list of supported languages.

for example, rule supported languages: ^.*(sv|ne|nb|pl|en).*$.

this example accept-language header: no-nb, en-us, en

the problem i'm facing gives me last match, en string. need first match nb in case.

here regex fiddle illustrates issue.

note i'm matching part of no-nb language code on purpose.

you can use regex:

^.*?(sv|ne|nb|pl|no|en).*$    ^--- note '?' use non-greedy quatifier 

http://regex101.com/r/up5dn5/2


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -