2

Edit: Sorry, should have given more information

Is it possible to replace only the english text here?

{ "question": "本能", "answers":[ "ほんのうInstinct" ] },

I want it to just be { "question": "本能", "answers":[ "めがね" ] }, and keep the other english text.

Tried [A-Za-z]+ and it works for all english text, but I don't know how to select a certain section. I'm using find and replace on notepad+

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
PierceJ
  • 95
  • 9

3 Answers3

1

this is your regex: /[A-Za-z]*/g

var s = '":[ "めがねGlasses" ] },'

console.log(s.replace(/[A-Za-z]*/g, ''))
jdubjdub
  • 613
  • 7
  • 21
1

You can replace everything that matches /[a-z]/gi by an empty string.

The flags g and i respectively means that you want to match multiple times and you want to be case insensitive.

You also could use \w shortcut which stand for word character, but this will also match [0-9_] which you may not want to delete.

Here is a working exemple of the regex.

Ulysse BN
  • 10,116
  • 7
  • 54
  • 82
1

You may use

(?:\G(?!^)|"answers"\s*:\s*\[\s*")[^"]*?\K[a-zA-Z]+

and replace with an empty string.

Details:

  • (?:\G(?!^)|"answers"\s*:\s*\[\s*") - the end of the previous successful match (\G(?!^)) or (|) "answers" substring, 0+ whitespaces, :, 0+ whitespaces, [, 0+ whitespaces, " (see "answers"\s*:\s*\[\s*")
  • [^"]*? - any 0+ chars other than ", as few as possible (as *? is a lazy quantifier)
  • \K - a match reset operator discarding all text matched so far from the match buffer
  • [a-zA-Z]+ - 1 or more ASCII letters

Test:

enter image description here

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563