Capturing seperators with regex

  • Thread starter Thread starter Nightcrawler
  • Start date Start date
N

Nightcrawler

I have the following regular expression: (\s+-\s+|\s+\/\s+|\s+\\\s+|
\t)

Is there a better way to write this? I am looking to capture the
following characters - / \ and tab. There can be 0, 1 or more space
before and after these seperators.

Right now it captures these characters if there is a 1 or more spaces
before and after each seperator. However, there are instances where
there will be 0 spaces before or after or both before and after.

Thanks
 
Nightcrawler said:
I have the following regular expression: (\s+-\s+|\s+\/\s+|\s+\\\s+|
\t)

Is there a better way to write this? I am looking to capture the
following characters - / \ and tab. There can be 0, 1 or more space
before and after these seperators.

How about this?
"\\s*(?:[-/\\t]\s*)+"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top