Reply to post

regex for numbers with spaces and letter O

Author
vanguy
User
  • Total Posts : 0
  • Reward points: 0
  • Joined: 2021/10/15 12:14:25
  • Status: offline
2021/10/15 14:12:24 (permalink)

regex for numbers with spaces and letter O

I am reading a fantasy light novel and they put the stats in weird formats. The numbers will separated by space or the zero sometimes is the letter 'O'. Is there a regex that can fix the numbers so voice aloud will read it correctly instead of number by number or saying the letter 'O' ?
example
Race: Orc
Strength: 1 9 5
Mana: 6 O 9 O O 
Experience:  3OO,OOO,128
 
should become
 
Race: Orc
Strength: 195
Mana: 60900
Experience: 300,000,128
 
 
 
 
 
post edited by vanguy - 2021/10/15 14:14:33

2 Replies Related Threads

    Admin
    Administrator
    • Total Posts : 275
    • Reward points: 0
    • Joined: 2010/11/22 00:00:00
    • Location: USA
    • Status: offline
    Re: regex for numbers with spaces and letter O 2021/10/15 16:19:58 (permalink)
    This is a really tricky and interesting problem, to do with RegEx! I found out that 3 replacement are needed in exactly the order given below, to achieve this. See below, and when entering them, remember that there can't be any spaces in the Pattern or Replace fields, only the characters that I marked in bold, and be sure to distinguish the capital O letter from the narrower 0 (zero).
     
    First replace multiple O O sequences with 00:
     
    Type: Regular Expression (RegEx)
    Pattern: O\s*O
    Replace: 00
     
    Then replace remaining O with 0, if they are preceded by a digit:
     
    Type: Regular Expression (RegEx)
    Pattern: (\d\s*)(O)
    Replace: $10
     
    Finally remove the spaces between digits:
     
    Type: Regular Expression (RegEx)
    Pattern: (\d)(\s+)(?=\d)
    Replace: $1
     
    Greg
     
    vanguy
    User
    • Total Posts : 0
    • Reward points: 0
    • Joined: 2021/10/15 12:14:25
    • Status: offline
    Re: regex for numbers with spaces and letter O 2021/10/18 12:41:49 (permalink)
    thank you ! i will try it.  This is one of the example chapter https://freewebnovel.com/...-no-mi/chapter-29.html
    Jump to:
    © 2024 APG vNext Commercial Version 5.1