return only Digits 0-9 from a String

后端 未结 8 1809
遇见更好的自我
遇见更好的自我 2020-11-27 04:53

I need a regular expression that I can use in VBScript and .NET that will return only the numbers that are found in a string.

For Example any of the following \"str

相关标签:
8条回答
  • 2020-11-27 05:14

    I don't know if VBScript has some kind of a "regular expression replace" function, but if it does, then you could do something like this pseudocode:

    reg_replace(/\D+/g, '', your_string)
    

    I don't know VBScript so I can't give you the exact code but this would remove anything that is not a number.

    EDIT: Make sure to have the global flag (the "g" at the end of the regexp), otherwise it will only match the first non-number in your string.

    0 讨论(0)
  • 2020-11-27 05:20

    By the looks of things, your trying to catch any 10 digit phone number....

    Why not do a string replace first of all on the text to remove any of the following characters.

    <SPACE> , . ( ) - [ ] 
    

    Then afterwards, you can just do a regex search for a 10 digit number.

    \d{10}
    
    0 讨论(0)
提交回复
热议问题