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
Post a Comment