Hello there Regex Experts!
Your help end experience is needed
I have a following SIP header:
Accept-Language: en, da, en-gb;q=0.8, fr, en;q=0.7
Accept-Language: en
Accept-Language: fr, en, da
I need to find all varieties of english within. That is : en, en-gb;q=0.8 and en;q=0.7
What will be a regex for doing so?
PS: Regex engine runs on FreeBSD machine
Thanks in advance
HowTo find an English (en) within Accept-Language header
Moderator: General Moderators
-
evgeny1976
- Forum Newbie
- Posts: 2
- Joined: Mon Apr 20, 2009 2:48 am
Re: HowTo find an English (en) within Accept-Language header
this maybe an understatement but if all of em contain "en" just run a simple regex for "/en/"
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: HowTo find an English (en) within Accept-Language header
Since this is a PHP/regex forum, here's a PHP way:
Code: Select all
preg_match_all('/en[^\s,]*/', 'Accept-Language: en, da, en-gb;q=0.8, fr, en;q=0.7', $matches);
print_r($matches);
/*
Array
(
[0] => Array
(
[0] => en
[1] => en-gb;q=0.8
[2] => en;q=0.7
)
)
*/-
evgeny1976
- Forum Newbie
- Posts: 2
- Joined: Mon Apr 20, 2009 2:48 am
Re: HowTo find an English (en) within Accept-Language header
Hi All!
Thanks a lot for your help!
The simplest en solution works!
Somehow Eclipse QuickRex tool confused me a little bit
Thanks a lot for your help!
The simplest en solution works!
Somehow Eclipse QuickRex tool confused me a little bit
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: HowTo find an English (en) within Accept-Language header
The regex "en" will only match the characters "en" and not the entire substring "en-gb;q=0.8". But if that is okay for you, there really is no need for regex: a simple string operation like stristr():evgeny1976 wrote:Hi All!
Thanks a lot for your help!
The simplest en solution works!
Somehow Eclipse QuickRex tool confused me a little bit
http://www.w3schools.com/PHP/func_string_stristr.asp
Re: HowTo find an English (en) within Accept-Language header
yh but its really irrelevant in here as nothing other than "en" will appear becuase its one of a kind