Regex to remove apostrophe

前端 未结 7 602
野性不改
野性不改 2021-01-22 13:10

I have input text that contains a \' like in this text \"Frank\'s Reel Movie Reviews\"

how do I get rid of the \'

I have tried

.replace (/\\\'/ig         


        
相关标签:
7条回答
  • 2021-01-22 14:07

    If you want something very selective to remove (or replace by anything like a space) apostrophes but not the symbol ' for feet imperial unit, use:

    val apostropheRegex = """(?<=[a-zA-Z])'(?=[a-zA-Z])"""
    "john's carpet is 5' x 8'".replaceAll(apostropheRegex, "XXX") // johnXXXs carpet is 5' x 8'
    

    It means "Replace all symbol ' that are between two letters".

    0 讨论(0)
提交回复
热议问题