Rules for building a regular expression from entries in the .ini file?

61 views
Skip to first unread message

JP

unread,
Jun 16, 2014, 4:28:47 PM6/16/14
to brow...@googlegroups.com
What are the rules for building a regular expression from the entries in the .ini file?

Based on various code snippets I've looked at, here's what I am replacing:

. -> \.
* -> .*
? -> .
( -> \(
) -> \)
[ -> \[
] -> \]
+ -> \+

Questions:

1. Are there any other characters that I need to convert?

2. When should I match start/end of string? (with ^ and $)

3. Are there any docs for how the .ini file is constructed that might help?


I am doing this because the code I was using for ColdFusion (browscap.cfc) was not matching the user agent: "Safari 5.1.9, Mac OS X 10.6.8" correctly. I believe the correct entry in the .ini file is: [Safari 5.1]. In this case, the regex could be: "Safari 5.1.*" but should not be "^Safari 5.1.*"

James Titcumb

unread,
Jun 16, 2014, 5:37:19 PM6/16/14
to browscap

Hi there!

The regexes should assert start and end of string all the time (with ^ and $ as you mentioned), I know that off my head, and the mapping you have there looks about right.

That particular UA is not designed to be matched directly - the "children" of that UA should match. The UA "Safari 5.1.9, Mac OS X 10.6.8" is not a valid UA, so would not match anything. Safari UA at least starts with "Mozilla..." like most browser UAs.

It might be worth looking at the way https://github.com/browscap/browscap-php parses the INI file :)

HTH, thanks
James

--
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.

Reply all
Reply to author
Forward
0 new messages