<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://regexadvice.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Construction Advice</title><link>http://regexadvice.com/forums/68/ShowForum.aspx</link><description>&lt;P&gt;Find help building expressions to suit your needs. Consult the &lt;A href="http://regexlib.com"&gt;Regular Expression Library&lt;/A&gt; to find many pre-built expressions, and add your own once you've solved your construction problem in our forum.&lt;/P&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2.1 (Build: 60809.935)</generator><item><title>Re: pattern matching problem</title><link>http://regexadvice.com/forums/thread/84987.aspx</link><pubDate>Wed, 18 Apr 2012 03:28:46 GMT</pubDate><guid isPermaLink="false">d291b357-6366-4006-9008-4266c301325a:84987</guid><dc:creator>Aussie Susan</dc:creator><slash:comments>0</slash:comments><comments>http://regexadvice.com/forums/thread/84987.aspx</comments><wfw:commentRss>http://regexadvice.com/forums/commentrss.aspx?SectionID=68&amp;PostID=84987</wfw:commentRss><description>&lt;p&gt;There are 2 things going on here.&lt;/p&gt;&lt;p&gt;The first is that the alternation operator has a very low precedence. This means that:&lt;/p&gt;&lt;p&gt;\s*\bStreet|Expy\b\s*&lt;/p&gt;&lt;p&gt;(which is a very cut down version of your pattern) will match 2 alternatives namely &amp;#39;\s*\bStreet&amp;#39; and &amp;#39;Expy\b\s*&amp;#39;. I suspect that you want the &amp;#39;\s*\b&amp;#39; at the start and the &amp;#39;\b\s*&amp;#39; at the end to apply to all of the alternatives in between. In that case you need to specify this as&lt;/p&gt;&lt;p&gt;\s*\b(Street|Expy)\b\s*&lt;/p&gt;&lt;p&gt;(obviously with all of the other alternatives added).&lt;/p&gt;&lt;p&gt;The second issue is why the pattern is matching the test string. If you look at what is actually being matched you will see that it is the characters &amp;quot;st&amp;quot;. Given what I said before, the &amp;quot;|St|&amp;quot; alternative is being seen by the regex engine as being the ONLY characters that are needed for this alternative to match. The way the regex engine works is to set a pointer to the start of the text and then try to see if the pattern can match starting from that point.&lt;/p&gt;&lt;p&gt;If it fails (as it will with your test string) the regex engine then advances the text pointer 1 step and tries the pattern again. This is repeated until either a match is made or the text pointer gets to the end of the string.&lt;/p&gt;&lt;p&gt;What is happening is that the text pointer is pointing to the &amp;quot;s&amp;quot; character in &amp;quot;destination&amp;quot; and the pattern is then trying each alternative in turn until it gets to the &amp;#39;|St|&amp;#39; one. As you have the &amp;quot;ignore case&amp;quot; option set, it will declare a match.&lt;/p&gt;&lt;p&gt;If you make the change I mentioned to the first problem, then this one will go away (i.e. the &amp;#39;\b&amp;#39; anchors will be applied to the start and end of each option and so will only match a complete &amp;quot;word&amp;quot; and therefore will not match the &amp;quot;st&amp;quot; characters within a word.&lt;/p&gt;&lt;p&gt;Susan&lt;/p&gt;</description></item><item><title>Re: pattern matching problem</title><link>http://regexadvice.com/forums/thread/84982.aspx</link><pubDate>Tue, 17 Apr 2012 16:06:04 GMT</pubDate><guid isPermaLink="false">d291b357-6366-4006-9008-4266c301325a:84982</guid><dc:creator>daiyue</dc:creator><slash:comments>0</slash:comments><comments>http://regexadvice.com/forums/thread/84982.aspx</comments><wfw:commentRss>http://regexadvice.com/forums/commentrss.aspx?SectionID=68&amp;PostID=84982</wfw:commentRss><description>&lt;p&gt;yes, I put the wrong string for testing. and I have another problem here see the following regex:&lt;/p&gt;&lt;p&gt;const wregex roadPat(L&amp;quot;\\s*\\bStreet|St|Avenue|Ave|Wharf|Boulevard|Blvd|Highway|Hwy|Road|Rd|Lanes|Gardens?|Gate|Place|Terrace|Rue|Bd|Harbour|Way|Common|Drive|Circle|Freeway|Loop|Expressway|Expy\\b\\s*&amp;quot;, regex_constants::icase);&lt;/p&gt;&lt;p&gt;I set up a work boundary here, but this regex will match the sample string&lt;/p&gt;&lt;p&gt;wstring wstrTxt34 = L&amp;quot;5.2 miles from destination &amp;quot;;&lt;/p&gt;&lt;p&gt;which is wrong, so how to fix this?&lt;/p&gt;&lt;p&gt;cheers&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: pattern matching problem</title><link>http://regexadvice.com/forums/thread/84972.aspx</link><pubDate>Mon, 16 Apr 2012 23:56:32 GMT</pubDate><guid isPermaLink="false">d291b357-6366-4006-9008-4266c301325a:84972</guid><dc:creator>Aussie Susan</dc:creator><slash:comments>0</slash:comments><comments>http://regexadvice.com/forums/thread/84972.aspx</comments><wfw:commentRss>http://regexadvice.com/forums/commentrss.aspx?SectionID=68&amp;PostID=84972</wfw:commentRss><description>&lt;p&gt;Ignoring the &amp;quot;wstrTxt34&amp;quot; vs. &amp;quot;wstrTxt33&amp;quot; situation, I have tried both of your patterns against the test string and both match.&lt;/p&gt;&lt;p&gt;As the pattern would seem to be correct, then you need to look at some of the other areas that can go wrong.&lt;/p&gt;&lt;p&gt;
It might be something to do with how the regex engine processes whitespace in the pattern (but I&amp;#39;m only guessing) - if the default is to &amp;quot;ignore whitespace&amp;quot; then the literal space character between (say) &amp;quot;from&amp;quot; and &amp;quot;destination&amp;quot; may be being ignored. You could alway s try replacing the space characters with &amp;#39;\s&amp;#39; (or &amp;#39;\s+&amp;#39;) to check this.
&lt;/p&gt;&lt;p&gt;You could also try a simpler pattern (say &amp;#39;\d+&amp;#39;) and check that it does find the correct characters. Then you can build it up slowly (say &amp;#39;\d+\.?\d*&amp;#39; as the next step) until you find what is not working.&lt;/p&gt;&lt;p&gt;Susan&lt;/p&gt;</description></item><item><title>pattern matching problem</title><link>http://regexadvice.com/forums/thread/84970.aspx</link><pubDate>Mon, 16 Apr 2012 16:11:47 GMT</pubDate><guid isPermaLink="false">d291b357-6366-4006-9008-4266c301325a:84970</guid><dc:creator>daiyue</dc:creator><slash:comments>0</slash:comments><comments>http://regexadvice.com/forums/thread/84970.aspx</comments><wfw:commentRss>http://regexadvice.com/forums/commentrss.aspx?SectionID=68&amp;PostID=84970</wfw:commentRss><description>&lt;p&gt;hi, I have a regex that matches strings like:&lt;/p&gt;&lt;p&gt;wstring wstrTxt34 = L&amp;quot;5.2 miles from destination &amp;quot;;&lt;/p&gt;&lt;p&gt;const wregex distPat(L&amp;quot;\\s*\\d+\\.?\\d*\\s*miles from destination\\s*&amp;quot;);&lt;/p&gt;&lt;p&gt;const wregex distPat2(L&amp;quot;\\s*\\d+\\.?\\d*\\s*miles\\s+(from destination)?\\s*&amp;quot;);&amp;nbsp;&lt;/p&gt;&lt;p&gt;if(regex_match(wstrTxt33, distPat))&lt;/p&gt;&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt;	&lt;/span&gt;m_strVIPSResult += CString(L&amp;quot;Distance&amp;quot;);&lt;/p&gt;&lt;p&gt;}&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;however, the regex cant match up with the string, and i cant find whats wrong with my regex. where went wrong, thx.&lt;/p&gt;&lt;p&gt;cheers&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>