Coder Guy
Coder Guy

Reputation: 1933

How to replace matches using Regexp::Grammars?

I am using Regexp::Grammars to search and extract information from a complex textual source, but ultimately I want to also make replacements on that source. Is there a way to accomplish this either directly or indirectly using Regexp::Grammars?

For example, suppose I have the following definition:

use Regexp::Grammars;
qr {
    <[element]>*

    <rule: element> 
        <target> | <word> | <bracket>

    <rule: target> 
        <define> \( (<word>)* \)

    <token: define>
        define

    <token: word>
        \w+

    <token: bracket>
        [()]
}xm

How would I replace all <target>s with some replacement that is say a function of the <word> between the brackets?

Upvotes: 2

Views: 109

Answers (0)

Related Questions