473,320 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Capturing seperators with regex

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
Jun 27 '08 #1
3 964
"Nightcrawler" <th************@gmail.comwrote:
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.
If you want 0, 1 or more (instead of just one or more) you should use *
instead of +. In a regular expression, * means "zero or more" and +
means "one or more".

Eq.
Jun 27 '08 #2
Nightcrawler wrote:
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*)+"
>
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

Jun 27 '08 #3
Thanks! That helped!
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
by: Joerg Schuster | last post by:
Hello, Python regular expressions must not have more than 100 capturing groups. The source code responsible for this reads as follows: # XXX: <fl> get rid of this limitation! if...
1
by: kevin | last post by:
I am trying to strip the outermost html tag by capturing this tag with regex and then using the string replace function to replace it with an empty string. while stepping through the code, RegEx...
2
by: Alexandre Brisebois (www.pointnetsolutions.com) | last post by:
Hi I'm trying to fix an expression, to grab all sets of 2 words with a space between them, ie: hello word (valid) C# sample (Valid) hello. world (Invalid) hello world. (invalid) <-- need to stop...
3
by: sklett | last post by:
I have this pattern: @"\s*//\$\$\s*Targets:\s*(+)" to match this line: //$$Targets: thing, thing+ When I get a match, the first Group (index 1, not 0) has: "thing, thing" - it drops the plus...
6
by: ffreino | last post by:
Hi, I'm trying to capture text between two words in a multi-line string. For example: 89. This is the text I would like to capture. This is another line. 90. End of the example. I would like...
2
by: GS | last post by:
How can one avoid capturing leading empty or blank lines? the data I deal with look like this "will be paid on the dates you specified. xyz supplier amount: $100.52 when: September 07,...
2
by: Advait Mohan Raut | last post by:
Hello friends, I am new to Regex engine. I use Expresso to test RE. For a named capturing test, I have following schema-- FullName --first , surname OR FullName --surname , first ,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.