ruby - How can I write a regular expression to detect a word within parentheses? Mine doesn't work. (Example given) -



ruby - How can I write a regular expression to detect a word within parentheses? Mine doesn't work. (Example given) -

i want observe word apple if word apple appears anywhere within curly parentheses ({...}). these parentheses can nested. she ate apple should not match, while she ate {food:apple} should , she stole {foods{apple}} should.

i wrote /\{[^{}]*?(?:\{apple?\})*?[^{}]*?\}/i, matches anything appears within curly parentheses, , i'm not sure how prepare it.

edit: using ruby. in next example:

this line apple in shouldn't match. line ${the.word.apple} in should. line ${something.else} should not match.

only line 2 should match. problem getting false match on line 3.

you can utilize regex:

\{[^}]*?apple[^}]*\} ruby regex demo

ruby regex

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -