Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 19-03-2011, 04:33 PM   #1 (permalink)
Alpha Geek
 
Join Date: Jan 2007
Location: In your hearts
Posts: 828
Default Regular expressions in python


hello everybody, I want to create a regular expression (in Python) for which I select all the string in between
/* and */ including all spaces, tabs, newline etc.
for example,
/* HELLO */
/* HELLO
EVERYONE */
these should be selected with and without \n. I have trying for 2 hrs and still trying. I was able to achieve without newline character, i.e. I can get string /* HELLO */ but not
/* HELLO
EVERYONE */
I did the following

/\*(\w+\s*+\n*)+\*/

/\*[\w+\s*+\n*]+\*/


any many other do not remember all that.
Please write that regular expression for me!!
abhijangda is online now   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 20-03-2011, 10:14 AM   #2 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
Default Re: Regular expressions in python

i dont work on python but in C#, the entire text can be represented as a string with escape sequence
/t = tab
/n = new line

the string would look something like ::
/* HELLO/nEVERYONE */
and that works for the regex
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
arpanmukherjee1 is offline   Reply With Quote
Old 27-03-2011, 08:29 PM   #3 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Smile Re: Regular expressions in python

Quote:
Originally Posted by abhijangda View Post
I did the following

/\*(\w+\s*+\n*)+\*/

/\*[\w+\s*+\n*]+\*/
It is a simple matter of iterating over issues and building your solution.
Starting off, you will want to match 'any' string, not characters belonging to a set (A simple .* within comments, perhaps). Next, you'll need to handle detection of newline characters (\r as well as \n, if you may).

Then you'll need to understand that regex is greedy, since it would now be matching against multiple comments spread in a document (A /**//**/ would be matched as a single one). Once you've figured out a way to avoid THAT, you'll need to find a way to support comments that have multiple '*'s in them, a common sight for multi-line comments from IDEs/code-editors.

By now it would be a complex regex that STILL would not do it all for you (multiple ending *s in a line? boom!). But anyways, what are you gonna use it for?

Quote:
Originally Posted by abhijangda View Post
Please write that regular expression for me!!
We could write it down for you, but that'd defeat the purpose of this board wouldn't it? But well, you can always search the web - your problem isn't unique.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx
- by clinton

Advertisement




All times are GMT +5.5. The time now is 12:24 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2