#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Remove number out of a paragraph


    Hi,

    I am struggling to find a expression which basically removes number/decimals from a paragraph.

    Eg: jack and1 jill 233 up 3.4 hill. dsf234 sfd 4345 dsf67sdf.

    output: jack and1 jill up hill. dsf234 sfd dsf67sdf.

    Bold letters gone.

    Experts.. Please help.
  2. #2
  3. Turn left at the third duck
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Location
    Nelson, NZ
    Posts
    112
    Rep Power
    93
    Hi Sudhanvag,

    Search: (^|\s+)\d+\.?\d+(\s+|$)
    Replace: a single space

    This will work on your string, where numbers are surrounded by spaces. This will also work when numbers fall at the beginning and end of the string.

    If you find a case where this does not work for you, post it and we'll tweak the regex. (It's impossible to know all the twists and turns of your input without seeing it.)

    Wishing you a fun day

  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0
    Thanks for the reply bro.

    The out of the RegEx is
    "jack and1 jill up hill. dsf234 sfd dsf67sdf"

    If you notice, decimal (.) remained. Need to remove that aswell.
  6. #4
  7. Turn left at the third duck
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Location
    Nelson, NZ
    Posts
    112
    Rep Power
    93
    Hey bro,

    I don't think I understand, can you please explain?
    The dot (.) that remains is not a decimal point: it's the period in "hill."

    Are you saying that you also want to remove all periods? That's a different task. Let me know.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0
    My Bad.

    Thanks a lot for all the help. Will keep updated if needed.
  10. #6
  11. Turn left at the third duck
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Location
    Nelson, NZ
    Posts
    112
    Rep Power
    93
    No worries!
    Yes, please don't hesitate to ask if you'd like more help.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0
    Data can have numbers e.g. " 2 3 ewr4 3we er3er 4.5 5 sdf"

    In such case it is not working.

    e.g. and output below:
    " 6 7 jack 6 and1 6 8 jill 7 233 up 3.4 7.8 9.00 7.89 sfd 4345 dsf67sdf 6.7 8.7 "
    output:
    " 6 7 jack 6 and1 6 8 jill 7 up 7.8 7.89 sfd dsf67sdf 8.7 "

    please help.
  14. #8
  15. Turn left at the third duck
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Location
    Nelson, NZ
    Posts
    112
    Rep Power
    93
    Hi, just had a quick look: try this, it works for me.

    Code:
    (?<=^|\s)\d+(?:\.\d+)?(\s+|$)
    Replace with a single space.

IMN logo majestic logo threadwatch logo seochat tools logo