Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing subpatterns in replacement function #5

Closed
marcodings opened this issue Aug 6, 2015 · 2 comments
Closed

Accessing subpatterns in replacement function #5

marcodings opened this issue Aug 6, 2015 · 2 comments

Comments

@marcodings
Copy link

Direct manipulation of subpatterns is supported

  patterns: [
    {
      match: /(\w+)\s(\w+)/,
      replacement: '$2, $1' // replaces "John Smith" to "Smith, John"
    }

Id like to use the matched subpatterns in the replacement function, using $2 is taken literally and does not work
is there / please provide a way to access the subpatters via an variable array of sorts ?

{
                            // <!-- INC menu_main-symbols.inc -->
    match:                   /(<!--\s+INC )([^\s]+)(\s+-->)/g,
    replacement: fs.readFileSync('./src/include/$2', 'utf8')
},
@outaTiME
Copy link
Owner

outaTiME commented Aug 6, 2015

hi pal,

you could try the following or something like that:

{
  match: /(<!--\s+INC )([^\s]+)(\s+-->)/g,
  replacement: function(match, p1, p2, p3, offset, string) {
    return fs.readFileSync('./src/include/' + p2, 'utf8')
  }
},

@marcodings
Copy link
Author

Thanks, worked as a charm.
much appreciated !!!
On 15/08/06 17:37, Ariel Falduto wrote:

hi pal,

you could try the following:

{
match: /()/g,
replacement: function(match,p1,p2,p3,offset,string) {
fs.readFileSync('./src/include/' + p2,'utf8')
}
},


Reply to this email directly or view it on GitHub
#5 (comment).

mvg Marco

Ir. M.C. Dings
Dings-IT Solutions BV.
Kvk: 12068086
BTW: NL818459104B01
Mobile 06-5103.1175
Jankushofstraat 40
6002 CV Weert

@outaTiME outaTiME closed this as completed Aug 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants