Oh one more thing, neither of these simple examples actually test for the context of the parenthes (opening vs closing) ... ie. <node>)foo(</node> or <node>a paren)(((()))</node> will count as true ...
If you need to test matching parenthesis and account for the above I think you will need a more complex parser ----------------------------------------------------------------------------- David Lee Lead Engineer MarkLogic Corporation [email protected] Phone: +1 812-482-5224 Cell: +1 812-630-7622 www.marklogic.com<http://www.marklogic.com/> From: [email protected] [mailto:[email protected]] On Behalf Of David Lee Sent: Sunday, June 30, 2013 11:09 AM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] check for opening and closing Parentheses A totally different way, likely slower let $n := <node>(1 + (2 * 3)) / (x)</node> return fn:string-length( fn:replace( $n/string() , "[^(]","" ) ) eq fn:string-length( fn:replace( $n/string() , "[^)]","" ) ) Also I suspect your question is more complex. If you're really wanting to match parenthesis are you looking at a string representation of some kind of programming or expressio language ? If so you will need to take into account quoting and escaping ... that's a lot harder. ----------------------------------------------------------------------------- David Lee Lead Engineer MarkLogic Corporation [email protected] Phone: +1 812-482-5224 Cell: +1 812-630-7622 www.marklogic.com<http://www.marklogic.com/> From: [email protected] [mailto:[email protected]] On Behalf Of David Lee Sent: Sunday, June 30, 2013 11:04 AM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] check for opening and closing Parentheses let $n := <node>(1 + (2 * 3)) / (x)</node>, $cp := fn:string-to-codepoints($n/string()) return count( $cp[. eq 40 ] ) eq count( $cp[ . eq 41 ] ) ----------------------------------------------------------------------------- David Lee Lead Engineer MarkLogic Corporation [email protected] Phone: +1 812-482-5224 Cell: +1 812-630-7622 www.marklogic.com<http://www.marklogic.com/> From: [email protected] [mailto:[email protected]] On Behalf Of sini narayanan Sent: Sunday, June 30, 2013 1:05 AM To: MarkLogic Developer Discussion Subject: [MarkLogic Dev General] check for opening and closing Parentheses Hi All, How do i make sure that if a node value has 'n' opening Parentheses , it has equal number of closing Parentheses ? Is there an easy way to achieve this other than checking with fn:contains? Thanks, Sini
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
