473,785 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regex - Matching Multiline Comments

3 New Member
Hi ,

I am a starter with perl on windows.
I need to match commented lines like below

/* comments
* comments
comments */

Whats the exact reg exp in windows perl script to use for this.

I tried
($parm eq "\/*.*\n")
$parm =~ \^\/*.*\n/

Please let me know if you have a solution.

Thanks
Anilga
Aug 29 '07 #1
4 3072
KevinADC
4,059 Recognized Expert Specialist
the * is a special character in a regexp, if you want to match it you must escape it:

Expand|Select|Wrap|Line Numbers
  1. if (/^\/\* \w+/)
matches: "/* comment"

but by looking at what you posted you either made a mistake or don't understand how to write a reular expression because this is incorrect:

Expand|Select|Wrap|Line Numbers
  1. $parm =~ \^\/*.*\n/
Aug 29 '07 #2
anilga
3 New Member
Hi,

Thanks for the comments. I tried this:

Expand|Select|Wrap|Line Numbers
  1. while ($parm = <FILE>) {
  2.  
  3.     if( $parm eq /^\/\* \w+/) {
  4.         next;
  5.     }
  6.     print $parm;
  7.  
and I couldn't match.
Aug 29 '07 #3
KevinADC
4,059 Recognized Expert Specialist
if( $parm =~ /^\/\* \w+/)
Aug 29 '07 #4
miller
1,089 Recognized Expert Top Contributor
You can probably use the following reference to get what you want. It will help if you get some understanding of regular expressions before using this.

perlfaq6 - How do I use a regular expression to strip C style comments from a file?

- Miller
Aug 29 '07 #5

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

Similar topics

4
329
by: Masahiro Ito | last post by:
I have attached a block of text similar to the type that I am working with. I have been learning a lot about Regex - it is quite impressive. I can easily capture bits of info, but I keep having trouble with line breaks. I want to identify the start and end of blocks of text. Are there some tips someone can share? EG: in my text, I can grab a collection of everyones Phone number with:
0
1172
by: Andy | last post by:
Hi All I have a urgent problem with the regex object. I am currently reading in source code files (complete file including newline characters) as plain text into a string. i am then using a regex object to remove c-style multiline comments of the form /* ... */. My regular expression is /\*.*?\*/ and i have also turned on the regex singleline option that allows the dot character to match newline characters. the Regex is not matching the RE....
2
1876
by: Mr.Clean | last post by:
I am working on modifying a syntax highlighter written in javascript and it uses several regexes. I need to add a language to the avail highlighters and need the following regexes modified to parse the new language, Delphi/Pascal. Source to the highlighter is avail here: http://www.dreamprojections.com/SyntaxHighlighter/Default.aspx ********************************************** COMMENTS
1
9011
by: David Elliott | last post by:
I have an expression that works for single line but not multiline. What am I missing? expression = "<div(?<data1>.*?)>(?<data2>.*?)</div>"; MatchCollection mc = Regex.Matches(data, expression, RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); Expression works if data looks like this:
2
1868
by: Daniel Billingsley | last post by:
First, if MSFT is listening I'll say IMO the MSDN material is sorely lacking in this area... it's just a whole bunch of information thrown at you and you're left to yourself as to organizing it in your head. Typical learning starts with basics and progresses through increasingly complex information - I think given the inherent confusion-inducing ability of regex that kind of documentation would be very valuable. But anyway, I'm trying...
2
1650
by: Mortimer Schnurd | last post by:
Hi All, I am a VB 6 programmer who is now trying to learn C#. In doing so, I am trying to convert some of my VB modules to C#. I routinely user Reg Expressions in VB and am having some trouble trying to use Regex in C#. Basically, I have a fixed format text file which I need to validate prior to using in a program. The validation insures the data format matches what the program is expecting to find in the file. The pattern I am trying to...
8
2592
by: Bob | last post by:
I need to create a Regex to extract all strings (including quotations) from a C# or C++ source file. After being unsuccessful myself, I found this sample on the internet: @"@?""""|@?"".*?(?!\\).""|''|'.*?(?!\\).'" I am inputting the entire source file string and using it with RegexOptions.Singleline. This works OK with, unless the string ends with a back-slash. For example: "This is a test\\". Can anybody see how to fix this...
6
5899
by: Martin Evans | last post by:
Sorry, yet another REGEX question. I've been struggling with trying to get a regular expression to do the following example in Python: Search and replace all instances of "sleeping" with "dead". This parrot is sleeping. Really, it is sleeping. to This parrot is dead. Really, it is dead.
7
2431
by: MrNobody | last post by:
I'm trying to do some regex in C# but for some reason linebreaks are causing my regex to not work. the test string goes like this: string ss = "<tagname something=45678&somethingelse=12345>blah</tagname>\r\n<tag2>stuff</tag2>"; and my regex code is like:
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
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...
1
10091
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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
8972
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...
1
7499
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
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
5381
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
4050
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

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.