Boost Regex - Alternation documentation example

Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Boost Regex - Alternation documentation example

Boost - Users mailing list
According to the Boost Regex documentation for Alternation
(http://www.boost.org/doc/libs/1_64_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html#boost_regex.syntax.perl_syntax.alternation)

Quoting a piece of the documentation:

-----

|abc is not a valid expression, but

(?:)|abc is and is equivalent, also the expression:

(?:abc)?? has exactly the same effect.

-----


Is the last expression:

   (?:abc)??

correct?  Why does it need two '?' operators instead of only one?

If I try this expression with the input "abc" the Boost engine does not
match "abc" as I'd have expected.  However the expression:

   (?:abc)?

matches as expected.



Nick


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Boost Regex - Alternation documentation example

Boost - Users mailing list


On 15/07/2017 14:12, Nick via Boost-users wrote:

> According to the Boost Regex documentation for Alternation
> (http://www.boost.org/doc/libs/1_64_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html#boost_regex.syntax.perl_syntax.alternation)
>
> Quoting a piece of the documentation:
>
> -----
>
> |abc is not a valid expression, but
>
> (?:)|abc is and is equivalent, also the expression:
>
> (?:abc)?? has exactly the same effect.
>
> -----
>
>
> Is the last expression:
>
>     (?:abc)??
>
> correct?

Yes.

> Why does it need two '?' operators instead of only one?

Non-greedy, matches nothing for preference, otherwise abc, same as
"(?:)|abc" does.
>
> If I try this expression with the input "abc" the Boost engine does not
> match "abc" as I'd have expected.  However the expression:
>
>     (?:abc)?
>
> matches as expected.

That has the opposite semantics: abc as first choice, nothing as
second.  ie the same as "abc|(?:)".

HTH, John.

---
This email has been checked for viruses by AVG.
http://www.avg.com

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Boost Regex - Alternation documentation example

Boost - Users mailing list
Somehow I didn't get this reply for a while.


On Sat, 2017-07-15 at 15:44 +0100, John Maddock via Boost-users wrote:
>
> On 15/07/2017 14:12, Nick via Boost-users wrote:
> > Why does it need two '?' operators instead of only one?
>
> Non-greedy, matches nothing for preference, otherwise abc, same as
> "(?:)|abc" does.

Good to know, thanks.  Makes me wonder what scenario(s) that would be
useful for


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Loading...