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

Home Posts Topics Members FAQ

How to search a regex without replacing it in perl

2 New Member
I want to search a regex in perl without replacing it and without going line by line to search it

Any help will be apriciable

Thanks in advance
Feb 3 '09 #1
7 1680
Icecrack
174 Recognized Expert New Member
Question:
What have your tried so far?

How can we work with what you want, if we do not know the information we are looking for?

Thanks

Charlie
Feb 3 '09 #2
KevinADC
4,059 Recognized Expert Specialist
You can't search a regexp, the question makes no sense. You can search a file or a database, but you can't search a regexp.
Feb 3 '09 #3
Vipul03
2 New Member
I have tried to serch each and every line in the file using

Expand|Select|Wrap|Line Numbers
  1. open FH,"log";
  2. for $line(<FH>){
  3. if( $line =~ m/regexp/ )
  4. {
  5. }
  6. }
but i dont want to look each and every line in the file

Thanks
Feb 3 '09 #4
numberwhun
3,509 Recognized Expert Moderator Specialist
@Vipul03
If you don't try and match against every line, how are you going to have a proper search? Inside of the if statement, if you don't do anything, like print the line or the line number, then you will never know that there was a match.

Regards,

Jeff
Feb 3 '09 #5
KevinADC
4,059 Recognized Expert Specialist
maybe this is what you want, hard to say because I guess you think we can read your mind and understand your vague question:

Expand|Select|Wrap|Line Numbers
  1. open FH,"log";
  2. while (my $line = <FH>){
  3.    if( $line =~ m/regexp/ ) {
  4.       "Found regexp in $line\n";
  5.       last; $stops searching after first match
  6.    }  
  7. }
  8. close FH;
  9.  
If thats not what you are trying to do then please explain yourself properly so other people can understand what your requirements are.
Feb 3 '09 #6
Icecrack
174 Recognized Expert New Member
@KevinADC
I know in the quick making of that script you may of made a mistake or typo at
Expand|Select|Wrap|Line Numbers
  1. $stops Searching
Feb 3 '09 #7
KevinADC
4,059 Recognized Expert Specialist
@Icecrack
Yes thanks, should have been "#stops searching" instead of "$stops Searching".
Feb 3 '09 #8

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

Similar topics

13
4537
by: David Morgan | last post by:
Hello I have a little function to highlight text if it exists. Function Highlight(vFind, vSearch) Dim RegEx Set RegEx = New RegExp RegEx.Pattern = vFind RegEx.IgnoreCase = True Highlight = RegEx.Replace(vSearch, "<span class=""Highlight"">" & vFind &
0
1218
by: Xah Lee | last post by:
in the regex module re: Note: Match() is not exactly equivalent to Search() with "^". For example: re.search(r'^B', 'A\nB',re.M) # succeeds re.match(r'B', 'A\nB',re.M) # fails if without the re.M, would re.search and re.match be equivalent?
32
14899
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
17
3980
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher http://forta.com/books/0672325667/
2
1704
by: Mike Hildner | last post by:
I'm receiving bytes over a socket and displaying in a text box. In the responses I receive, some lines are delimited with x0A and others with x0D0A. I'd like to search for x0A and replace with x0D0A, but only if x0A is preceeded with x0D - so I don't end up with x0D0D0A. Right now I'm searching for x0D0A, replacing with x0A, then searching for x0A and replacing with x0D0A. Seems a little ugly. Is there a better way to do this? I...
3
8261
by: Craig Buchanan | last post by:
Is there a way to combine these two Replace into a single line? Regex.Replace(Subject, "\&", "&amp;") Regex.Replace(Subject, "\'", "&apos;") Perhaps Regex.Replace(Subject, "{\&|\'}", "{&amp;|&apos;}") Thanks, Craig
4
4840
by: lucky | last post by:
hi there!! i'm looking for a code snipett wich help me to search some words into a particular string and replace with a perticular word. i got a huge data string in which searching traditional way mean to secrife lots of time in asp.net. can any one give me such a expression in which i pass a data string and search word string and replace word string? if so plz help me out. i'm in badly need.
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.
4
2646
by: Chris | last post by:
Hi Everyone, I am using a regex to check for a string. When all the file contains is my test string the regex returns a match, but when I embed the test string in the middle of a text file a match is never returned. The string that I give to the regex is one that contains the entire contents of a text file. I'm using the multi-line option and I've also tried stripping out the VbCr
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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
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...
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.