473,405 Members | 2,185 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,405 software developers and data experts.

hyphen in regular expression?

Hello!

The regular expression [a-c] matches on a, b or c. How to put a hyphen
itself as either a or c, i.e. something like [--c] (from hyphen to c)?
Best regards,

Henrik Dahl
Nov 15 '05 #1
3 2772
Simply escape the hyphen with a backslash:

[\--c]
Brian Davis
www.knowdotnet.com

"Henrik Dahl" <Th**********************@inet.uni2.dk> wrote in message
news:OE**************@TK2MSFTNGP09.phx.gbl...
Hello!

The regular expression [a-c] matches on a, b or c. How to put a hyphen
itself as either a or c, i.e. something like [--c] (from hyphen to c)?
Best regards,

Henrik Dahl

Nov 15 '05 #2
Hi Henrik,

Did you tried to "escape" it:

[a\-c]

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Henrik Dahl" <Th**********************@inet.uni2.dk> wrote in message
news:OE**************@TK2MSFTNGP09.phx.gbl...
Hello!

The regular expression [a-c] matches on a, b or c. How to put a hyphen
itself as either a or c, i.e. something like [--c] (from hyphen to c)?
Best regards,

Henrik Dahl

Nov 15 '05 #3
No, because the hyphen is not one of the characters which are enumerated to
be escapeable.

Best regards,

Henrik Dahl

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:uA**************@TK2MSFTNGP11.phx.gbl...
Hi Henrik,

Did you tried to "escape" it:

[a\-c]

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Henrik Dahl" <Th**********************@inet.uni2.dk> wrote in message
news:OE**************@TK2MSFTNGP09.phx.gbl...
Hello!

The regular expression [a-c] matches on a, b or c. How to put a hyphen
itself as either a or c, i.e. something like [--c] (from hyphen to c)?
Best regards,

Henrik Dahl


Nov 15 '05 #4

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

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
1
by: mm | last post by:
In a regular expression, is a hyphen simply - whereas a minus sign is \- I am trying to understand the code below: $addend_two = (rand 200) - 100; $addend_two =~ /(\-?+)\.?*/ ? $intPart2 =...
27
by: The Bicycling Guitarist | last post by:
Hi. I found the following when trying to learn if there is such a thing as a non-breaking hyphen. Apparently Unicode has a ‑ but that is not well-supported, especially in older browsers. Somebody...
4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
5
by: jayanthigk2004 | last post by:
Input a- Patterns \w*-* \w*(-*) \w*(-)* \w**
4
by: Peter | last post by:
Hi all, I am searching through directories trying to find the prefix to a number of files. Unfortunately the files don't have a standard naming convention yet. So some of them appear as:...
0
by: Andreas Prilop | last post by:
It seems to me that Internet Explorer 7 (as opposed to IE6) displays the non-breaking-hyphen U+2011 or ‑ as some sort of dash rather than a hyphen. See U+2011 #8209 at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.