What does \t and \x mean in the .ini file?

60 views
Skip to the first unread message

Nisrina Luthfiyati

unread,
26 Feb 2015, 10:29:41 am26/02/2015
to brow...@googlegroups.com
Hi all,
I'm trying to parse the user agent pattern in full_asp_browscap.ini file into regex.
I notice that some of the user agent patterns contains \t and \x, for example:
5.0 (*Mac OS X*) AppleWeb\t\tKit/* (KHTML,*like Gecko*) Version/*Safari/*
QQ\x*HD* (iPad; iPhone OS 4.3.3; *)*
Mojilla/5.0 (H11; U; Linux!x86_64;\xa0en-US+ rf:*) Gecko/* Firefox/2.*

Do the \t and \x means tab and hexadecimal characters or do they need to be escaped if I'm converting them to regex?

Thank you :)
Nisrina

James Titcumb

unread,
27 Feb 2015, 6:07:15 am27/02/2015
to browscap on behalf of Nisrina Luthfiyati
Without looking into it properly, I'm not sure - I'd say try either way and see what results you get :)

Thanks
James

Nisrina

--
You received this message because you are subscribed to the Google Groups "browscap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to browscap+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christopher Kennedy

unread,
6 Mar 2015, 11:40:26 pm06/03/2015
to brow...@googlegroups.com
I would also like to know what the \t and \x stand for. I've been scrounging through the discussions to find out how to convert the patterns to regex and it's not documented well.

While trying to port browscap to Scala, \x throws the following exception:

java.util.regex.PatternSyntaxException: Illegal hexadecimal escape sequence near index 4

The only remedy I could find is to replace \ with \\ to escape it, but this felt wrong. I looked through the PHP library, and it looks like \x is escaped.


/**
* Converts browscap match patterns into preg match patterns.
*
* @param string $user_agent
*
* @return string
*/
protected function _pregQuote($user_agent)
{
$pattern = preg_quote($user_agent, self::REGEX_DELIMITER);

// the \\x replacement is a fix for "Der gro\xdfe BilderSauger 2.00u" user agent match

return self::REGEX_DELIMITER
. '^'
. str_replace(array('\*', '\?', '\\x'), array('.*', '.', '\\\\x'), $pattern)
. '$'
. self::REGEX_DELIMITER;
Reply all
Reply to author
Forward
0 new messages