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

Allowing spaces in regular expression match.

Markus
6,050 Expert 4TB
I'm asking the question for once!

Say I have the expression @[^a-zA-Z0-9_-]@ that matches anything other than the characters specified. I also want spaces to be allows, including \n, \t, etc. I've tried adding a simple space into the expression such as @[^a-zA-Z0-9_- ]@, but that doesn't seem to work.

Anyone know how to do this? I could just match any disallowed characters, but I'd rather go this way.

Thanks,
Mark(us).
Dec 5 '08 #1
6 5421
Atli
5,058 Expert 4TB
I don't get it.

If you are specifying the characters that are *not* allowed, the expression should allow all white-spaces.

If you want them to be excluded, try adding a \s into the expression. That represents all white-space characters.

Maybe I'm just not getting the problem.
Haven't had any coffee today :P
Dec 6 '08 #2
Markus
6,050 Expert 4TB
@Atli

No, no. I'm specifying that characters that are allowed.

@Atli
Ah, there you go! Thanks, Atli.

@Atli
You solved the problem, even when you didn't understand!

:D
Dec 6 '08 #3
Atli
5,058 Expert 4TB
Ahh ok. I see now :)

Although, in your expression [^a-zA-Z0-9_-], I always thought the ^ char inverted the class... meaning that it represented everything but the specified chars.

That was using the Perl-compatible regex tho. Maybe your using something else?

Then again. I might still not be understanding.
(Still haven't had any coffee... trying to quit :P)
Dec 6 '08 #4
pbmods
5,821 Expert 4TB
@Markus
The hyphen has special meaning inside of square brackets, which might be what threw it off. Try moving the space before the hyphen, e.g.:

Expand|Select|Wrap|Line Numbers
  1. @[^a-zA-Z0-9_ -]@
  2.  
Alternatively, you can simply escape the hyphen:
Expand|Select|Wrap|Line Numbers
  1. @[^a-zA-Z0-9_\- ]@
  2.  
Dec 6 '08 #5
Markus
6,050 Expert 4TB
@Atli
Well, yeah. The characters that are in the regex are those that are allowed. The ^ character checks for anything other than the specified characters.
Dec 6 '08 #6
Markus
6,050 Expert 4TB
@pbmods
I'll give it a look. Thanks, Pb.
Dec 6 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: ajikoe | last post by:
Hello, For example I have a string : "Halo by by by" Then I want to take and know the possition of every "by" how can I do it in python? I tried to use: p = re.compile(r"by") m =...
3
by: Derek Stone | last post by:
In my continuing inability to completely understand regular expressions I have a new one for you. I'd like to capture a string "A" unless it is anywhere in between string "B" and string "C". ...
4
by: aliensite | last post by:
My code is too greedy, how can it be fixed? Here is my code: Desired output - First:,Second:,Third: <br> <script type="text/javascript"> var regEx = /*?:/g; var html = "<br>First:ratio<br...
4
by: Johnny Lee | last post by:
Hi, I've met a problem in match a regular expression in python. Hope any of you could help me. Here are the details: I have many tags like this: xxx<a href="http://xxx.xxx.xxx" xxx>xxx xxx<a...
5
by: Paul Johnston | last post by:
Hi Just started using c# to do a task I usually use Perl to do and hit a limit in my knowledge :-) I have a program which reads from a large text file, extracts certain lines then gets a string...
17
by: Randy Webb | last post by:
I know that the /g flag will match all occurrences. Is there a way, with a Regular Expression, to match all occurrences *except* the last one? pattern = /df/g; var myString = "asdfasdfasdfasdf";...
2
by: teo | last post by:
match word with interpunctuation Hallo, I need to build a regular expression able to match a specified word, preceded and followed by few chars (mainly interpunctuation) Below the code. ...
4
by: gfrith | last post by:
Hi, A quick regex question which I've worked around for the time being, but would like an answer to if anyone can help. I want to match on all strings which end _id, but not those ending...
2
by: Sal Sal | last post by:
If I have a string as follows XXXasdf23s5\r\n asdflkoirfn329i4\r\n sef29384ewrj28039\r\n XXX123sd3t334\r\n sdorfu23984rr\r\n sdflk2893rjf\r\n weirj2983jhwer2398\r\n XXX12356789\r\n
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...
1
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)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.