473,396 Members | 1,840 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,396 software developers and data experts.

Regexp query

170 100+
hey guys,

this is one regexp i did and it worked
but i dunno if it's correct
could anyone verfy

for the sentence in the file

/* 1 TB Hi VTP-10 SESSION=01471 USERID=##$@@# STARTED 2008-05-09 09:17:00 */

i want to match things between 1 TBHLR to USERID

so i used this
Expand|Select|Wrap|Line Numbers
  1. if ($data1 =~ /1 TBHLR.+USERID/)
  2.  
is this matching alright?
May 12 '08 #1
2 1107
nithinpes
410 Expert 256MB
The pattern you have used will match lines containing '1 TBHLR' followed by one/ more characters and then followed by 'USERID'. But if you want to extract characters between these two expressions, you have to group those characters and assign it to a variable as follows:
Expand|Select|Wrap|Line Numbers
  1. open(FILE,"data.txt") or die "opening file failed";
  2. while(<FILE>)  {
  3. if(/1 TBHLR(.+)USERID/)  {  ## group characters i between using parantheses
  4.   my $content=$1;  
  5. # $1 is the special variable carrying pattern matched inside
  6. # parantheses number 1.  
  7.   print "$content\n";   ### you can even print $1 directly
  8. }
  9. }
  10.  
There is no 'TBHLR' in the sample line that you provided :)
May 12 '08 #2
poolboi
170 100+
thanks!

yup.. i change my code forgot to change the TBHLR part
so since this syntaxt matches then i guess it's alright
just wanna get opinions if the syntax correct
May 13 '08 #3

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

Similar topics

10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
5
by: Lukas Holcik | last post by:
Hi everyone! How can I simply search text for regexps (lets say <a href="(.*?)">(.*?)</a>) and save all URLs(1) and link contents(2) in a dictionary { name : URL}? In a single pass if it could....
0
by: Ed Leafe | last post by:
I recently upgraded to 4.1 alpha (MySQL 4.1.0-alpha-standard-log) on my Linux server, and came across a problem with a query that had been working in 3.23 that no longer worked in 4.1a. I've...
6
by: Oliver Spiesshofer | last post by:
Hi, I would like to replace all strings in a table with regexp: the strings contain the substring "-na", and I would like to replace the whole table field with the original content but without...
1
by: Federico Bari | last post by:
Hello everyone, sorry for my bad English. I have to create a query under mySQL for a small research engine; I have to rate the results of a simple regular expression matches inside a text field....
0
by: Chris Croughton | last post by:
I'm trying to use the EXSLT regexp package from http://www.exslt.org/regexp/functions/match/index.html (specifically the match function) with the libxml xltproc (which supports EXSLT), but...
4
by: Jon Maz | last post by:
Hi All, I want to strip the accents off characters in a string so that, for example, the (Spanish) word "práctico" comes out as "practico" - but ignoring case, so that "PRÁCTICO" comes out as...
1
by: Good Man | last post by:
Hi there If I have a "Filename" column in a database, and I want to grab the EXTENSION of this filename... can I do it in a query using REGEXP or something similar? I've got this going: ...
0
by: problematic | last post by:
Hello guys Actually i dont know does mysql support prepare with regexp but i have this query. prepare stm from "select count(id) as total from products where content regexp ']?]' "; set @a =...
4
by: Matt | last post by:
Hello all, I have just discovered (the long way) that using a RegExp object with the 'global' flag set produces inconsistent results when its test() method is executed. I realize that 'global'...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.