I have a parsing question. I have sentences that are stored as Strings. I want to grab each word in each sentence however I would like to filter which words I grab. For example say I have a sentence like the following:
Hell0 3v3ryb0dy @ stackoverflow $people \implies queen$ equals ~queen --> ~people. /#logic
I would do the following:
- grab 'H3ll0'
- grab 3v3ryb0dy
- throw away the @
- grab 'people' from '$people'
- grab 'implies' from '\implies'
- grab 'queen' from 'queen$'
- grab 'equals'
- grab 'queen' from '~queen'
- throw away -->
- grab 'people' from '~people'
- grab 'logic' from '/#logic'
Essentially I want only alphanumeric characters and whenever I have some other character such as a \ before or after a word I want to disregard this other character.
Currently I am doing:sentence.split(" ")
This gets the individual words from the sentence but it grabs '$people' and '~people' and treats them differently when I want them to be treated the same.
- How can I achieve this?
- Would a regex help me here?