473,795 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 987
"Nightcrawl er" <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
5649
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 p.pattern.groups > 100: raise AssertionError( "sorry, but this version only supports 100 named groups"
1
3425
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 returns the entire input string although testing this in The Regulator returns just what I want. What am I doing wrong here? *********************************************** Regex regX; RegexOptions options = (RegexOptions.Multiline |...
2
1087
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 capture before the "." and cannot use \b since \b includes "#" this is the expression I am trying to work with, so far it takes each word fine seperately, but it does not take into account hello. world and it captured hello world.
3
1416
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 ('+'). Now, I don't know the plus will be there, everything after "Targets:" is variable and will change so I can't simply add an explicit check for it. What trick is there to get the special characters returned in the groups?
6
16112
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 to capture text between the words (numbers in this case) '89' and '90'
2
2817
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, 2007 reference #: 0415 from: operating account
2
1729
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 , middle eg. "advait raut" should return: first=advait surname=raut and "raut advait mohan" should return: first=advait middle=mohan
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10448
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6784
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.