Artikash / Textractor

Extracts text from video games and visual novels. Highly extensible.
GNU General Public License v3.0
2k stars 201 forks source link

Help regex filters #1228

Open iiuuoow opened 5 months ago

iiuuoow commented 5 months ago

The name is displayed at the back. I want to modify this to a regex filters.

original: 「にんげん? 食い止めるんだ!」 張世平【チョウセイヘイ】

want result: 張世平【チョウセイヘイ】 「にんげん? 食い止めるんだ!」

Maybe, It need 2 filters.

  1. specify the letter after 」.
  2. sending it to the front「 . But it was too difficult to me.please help!
Blu3train commented 5 months ago

Preserving multiple lines is complicated. Is a single line result OK? Like this 張世平【チョウセイヘイ】「にんげん?食い止めるんだ!」

Blu3train commented 5 months ago

In the regex file you have to put the carriage return as written here, between $3 and $1

|REGEX|(([^」]|\n)+」)((.|\n)+)|BECOMES|$3
$1|MODIFIER||END|
iiuuoow commented 5 months ago

Thank you! I want to apply it in JavaScript, is it like this?

const regex = /(([^」]|\n)+」)((.|\n)+)/; const input = 'YourInputStringHere';

const result = input.replace(regex, (match, group1, group2, group3) => { return group3; });

console.log(result);

Blu3train commented 5 months ago

I don't know, but surely in the return you must also add group1 in addition to group3 If you want to keep the carriage return 'maybe' like this return group3+'\n'+group1;

iiuuoow commented 5 months ago

Then, is it right if I write it like this?

|REGEX|(([^」]|\n)+」)((.|\n)+)|BECOMES|$3\r$1 $1|MODIFIER||END|

Blu3train commented 5 months ago

No, this

---start here
|REGEX|(([^」]|\n)+」)((.|\n)+)|BECOMES|$3
$1|MODIFIER||END|
---end here
iiuuoow commented 5 months ago

Thank you! However, test results are same,,

results : 「わかった。すぐに向かうわ」 関羽

iiuuoow commented 5 months ago

Thank you! However, test results are strange,,Maybe my JavaScript is the problem

results :

onEnter onEnter: 0 「関羽……」 onEnter onEnter: 0 劉備【リュウビ】 「関羽……」 劉備【リュウビ】

JavaScript const regexPattern = /(([^」\n]+)」)((.|[\n])+)/g;

let match; while ((match = regexPattern.exec(s)) !== null) { const modifiedString = match[3] + match[1]; s = s.replace(match[0], modifiedString); }

console.log(s);

Blu3train commented 5 months ago

maybe like this s.replace(/(([^」]|\n)+」)((.|\n)+)/g, '$3\n$1');

iiuuoow commented 5 months ago

Thank you for your efforts!!