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

regexOps clarification needed #83

Closed
Chilace opened this issue Dec 15, 2018 · 8 comments
Closed

regexOps clarification needed #83

Chilace opened this issue Dec 15, 2018 · 8 comments

Comments

@Chilace
Copy link
Contributor

Chilace commented Dec 15, 2018

These are feed settings:

"566000436feed43com>23537": {
  "title": "Sai 2.0 Development Feed",
  "link": "https://feed43.com/4432030375688680.xml",
  "channel": "204593356007931905",
  "addedOn": "2018-12-15T06:24:35.841Z",
  "message": "📰  |  **{title}**\n\n{description:newline}\n\n{link}\n\n{date}\n\n{subscriptions}",
  "regexOps": {
    "description": [
      {
        "name": "newline",
        "search": {
          "flags": "g",
          "regex": "\\s(\\[(?:Fixed|Changes|New)| *- )|\\*-- Delivered by Feed43 service\\*"
        },
        "replacement": "\n$1"
      }
    ]
  }
}

and that is what I get:
2018-12-15 15-51-45 playground - discord
Some test:
https://runkit.com/chilace/5c14d678cf5f680012b650f0
2018-12-15 16-13-41 regexops test runkit - google chrome

The question is how to replace matches with a captured group?

@Chilace
Copy link
Contributor Author

Chilace commented Dec 15, 2018

By the way, to see embedded code from RunKit you can install its app:
https://blog.github.com/2018-12-10-introducing-content-attachments-api/

@Chilace
Copy link
Contributor Author

Chilace commented Dec 16, 2018

In the meantime I will use this:
https://github.com/Chilace/Discord.RSS/commit/96dc9c73f1d72964ce1d750666b4b057ba29d956
You need "custom": true in the search object of the feed config for this to work, e.x.:

"566000436feed43com>23537": {
  "title": "Sai 2.0 Development Feed",
  "link": "https://feed43.com/4432030375688680.xml",
  "channel": "204593356007931905",
  "addedOn": "2018-12-15T06:24:35.841Z",
  "message": "📰  |  **{title}**\n\n{description:newline}\n\n{link}\n\n{date}\n\n{subscriptions}",
  "regexOps": {
    "description": [
      {
        "name": "newline",
        "search": {
          "custom": true,
          "flags": "g",
          "regex": "\\s(\\[(?:Fixed|Changes|New)| *- )|\\*-- Delivered by Feed43 service\\*"
        },
        "replacement": "\n$1"
      }
    ]
  }
}

2018-12-16 15-14-31 playground - discord

@synzen
Copy link
Owner

synzen commented Dec 16, 2018

To replace with a certain match and/or group, use the keys match and/or group

https://github.com/synzen/Discord.RSS/wiki/Custom-Placeholders-via-Regex-Ops#usagesyntax

image

@Chilace
Copy link
Contributor Author

Chilace commented Dec 17, 2018

It's not possible:

  1. Case:
"regexOps": {
  "description": [
    {
      "name": "newline",
      "search": {
        "flags": "g",
        "regex": "\\s(\\[(?:Fixed|Changes|New)| *- )|\\*-- Delivered by Feed43 service\\*",
        "group": 1
      },
      "replacement": "\n$1"
    }
  ]
}

2018-12-17 07-37-00 playground - discord
In this case match is [Fixed and captured group is [Fixed. Since new RegExp was created from this match/group I have not access to captured group in replacement string \n$1 and this new Regexp replaces only the first match from the original regex.

  1. Case:
"regexOps": {
  "description": [
    {
      "name": "newline",
      "search": {
        "flags": "g",
        "regex": "\\s(\\[(?:Fixed|Changes|New)| *- )|\\*-- Delivered by Feed43 service\\*",
        "group": 1
      },
      "replacement": "\n$&"
    }
  ]
}

Note - here I am trying to replace with the \n + last match
2018-12-17 07-48-41 playground - discord
In this case match is [Fixed and captured group is [Fixed. Since new RegExp was created from this match/group I'am trying replace with \n + last match \n$& and new Regexp replaces only the first match from the original regex.

But I need replace all matches (not groups) with first group in original regex and it's not possible if I specify the match/group.

Ok let's try this part of code:
https://github.com/synzen/Discord.RSS/blob/dev/structs/Article.js#L70
and replace with \n + lastmatch (since I have not access to groups in original regex):
2018-12-17 08-27-48 playground - discord


Below is the configured message to be sent for this feed:

--
:newspaper:  |  Sai 2.0 Development Feed
2018-05-26
 [Fixed Bugs]







 - [Resize Canvas] Internal data are corrupted when other canvas was closed after expansion of canvas size.







 - [Selection] Old selections are not deselected when do [Select All].







 - [View] The layouts of embedded views are corrupted after activated a floating view and next closed an embedded view.
 [Changes]







 - [Multicore Operation] Modulated the priority of each thread.







 - [Bristle] Re-tuned the quality and speed of the painting.







 - [Bristle] Improved the detection of turn.







 - [Brush Tools] Changed to apply [Blend] instead of [Dilution] to transparent color painting. (Changed to the behavior same as Ver.1.)







 - [Options Dialog] Added a checkbox [Do not hide separated panels when turned off [Show All User Interface Panels]].
-- Delivered by Feed43 service
https://www.systemax.jp/en/sai/devdept.html
вс, 16 декабря 2018, 3:20 дня MSK


In this case matches are:

0: [" [Fixed", "[Fixed"]
1: [" - ", "- "]
2: [" - ", "- "]
3: [" - ", "- "]
4: [" [Changes", "[Changes"]
5: [" - ", "- "]
6: [" - ", "- "]
7: [" - ", "- "]
8: [" - ", "- "]
9: [" - ", "- "]
10: ["*-- Delivered by Feed43 service*", undefined]

11 new instances of RegExp, every replacement of match - adds new line

@Chilace
Copy link
Contributor Author

Chilace commented Dec 17, 2018

Just for testing:
https://runkit.com/chilace/5c17349b4eec31001249ce8c

@Chilace
Copy link
Contributor Author

Chilace commented Dec 17, 2018

It is difficult to explain what I want in English.
I want to replace all matches in original {description} with a captured group in the original regexp.
(without creating a bunch of new regexp instances)

"regexOps": {
  "description": [
    {
      "name": "newline",
      "search": {
        "custom": true,
        "flags": "g",
        "regex": "\\s(\\[(?:Fixed|Changes|New)| *- )|\\*-- Delivered by Feed43 service\\*"
      },
      "replacement": "\n$1"
    }
  ]
}

with this commit https://github.com/Chilace/Discord.RSS/commit/96dc9c73f1d72964ce1d750666b4b057ba29d956

as a result:
2018-12-17 09-47-18 playground - discord

@synzen
Copy link
Owner

synzen commented Dec 20, 2018

Yes I understand now, try 62ddc26. Replace the replacement key in the regex op object with replacementDirect - it should function the same as your thing here

@Chilace
Copy link
Contributor Author

Chilace commented Dec 21, 2018

It works, thank you!
2018-12-21 15-01-44 playground - discord
@Macley-Kun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants