473,327 Members | 2,007 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.

Spaces and newlines in regular expressions

How can I signify a space or a newline in a regular expression? Are
they just represented by whitespace and \n?

Thanks!
Jul 17 '05 #1
3 2099
On Fri, 20 Aug 2004 10:55:20 -0700, Kyle wrote:
How can I signify a space or a newline in a regular expression? Are
they just represented by whitespace and \n?

Thanks!

Yup. Although you can also use \s for a space too, useful when looking for
the likes of '\s*' or '\s{1,8}' etc etc.

Something that might help you.. although I've posted it here before:
<http://weitz.de/regex-coach/>


Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #2
Kyle wrote:
How can I signify a space or a newline in a regular expression? Are
they just represented by whitespace and \n?

Thanks!


There's a character class "\s" that matches any whitespace character.
You can also use the regex form "/regex/s" to turn on PCRE_DOTALL, so
that the dot will match the "\n" newline characters as well. Note that
newlines are platform dependant and can be "\n" or "\r\n," etc...
--
Elliott C. Bäck
http://elliottback.com/
Jul 17 '05 #3
Ian.H wrote:
Something that might help you.. although I've posted it here before:
<http://weitz.de/regex-coach/>


Wow, this is great! Thank you!

Kyle
Jul 17 '05 #4

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

Similar topics

4
by: Christopher Finke | last post by:
I have a site wherein the clients can update the individual pages by editing the text of that page in a <textarea>. Then, when the page is displayed, all of the newlines (\n) are converted to HTML...
1
by: Shabam | last post by:
Is there a function in dotnet that allows me to trim user input so that: 1) It gets rid of leading/trailing spaces, tabs, newlines and whatever other non-printing characters 2) Gets rid of all...
10
by: John A Grandy | last post by:
What's the proper way to write a validation regex so that all leading and trailing spaces are trimmed before evaluation ? Thanks.
3
by: Chris Sharman | last post by:
Are spaces allowed in names ? Eg <input name="my field" type="text" value="my data"> The html4 dtd seems to say this is cdata, which allows embedded single spaces, but say agents may trim...
4
by: Manuel Reimer | last post by:
Hello, my problem is that spaces are always reduced to the size of one in html. I need some trick to make all spaces in a line visible. Something like this is possible with "<pre>" in HTML,...
15
by: Mark Rae | last post by:
Hi, I'm trying to construct a RegEx pattern which will validate a string so that it can contain: only the numerical characters from 0 to 9 i.e. no decimal points, negative signs, exponentials...
2
by: KDawg44 | last post by:
Hi, Normally I can write regular expressions decently well but for some reason I am having trouble getting this to work. I am validating form data and need to throw an error if there are ANY...
3
by: lex __ | last post by:
I'm tryin to use regexp to replace multi-line c-style comments (like /* this /n */ ) with /n (newlines). I tried someting like re.sub('/\*(.*)/\*' , '/n' , file) but it doesn't work for...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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
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...
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.