473,396 Members | 1,917 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.

how to match front and end of a sentence using regexp?

170 100+
hi, this is somewhat link to the other post i posted
but i shall put it in another topic for easy reference

previously i had

Expand|Select|Wrap|Line Numbers
  1. /* 4 ABC:DEFG=12334556,BSERV=T22; */
  2.  
i actualli used the regexp to match it

Expand|Select|Wrap|Line Numbers
  1.     foreach $data1 (@$data)
  2.     {
  3.       chomp ($data1); 
  4.     if ($data1 =~ /4 \D\D\D:/){
  5.       print "$data1\n";     
  6.       } }
  7.  
but right how can i just get
Expand|Select|Wrap|Line Numbers
  1.  
  2. ABC:DEFG=12334556,BSERV=T22;
  3.  
i tried using
Expand|Select|Wrap|Line Numbers
  1. $data =~ /\D\D\D.*;/;
  2.  
didn't work..so i'm not too sure about the syntax
May 14 '08 #1
6 1918
nithinpes
410 Expert 256MB
Use:
Expand|Select|Wrap|Line Numbers
  1. foreach $data1 (@$data)
  2.     {
  3.       chomp ($data1); 
  4.     if ($data1 =~ /4 (\D\D\D:.+)\*/){
  5.       print "$1\n";  # $1 will hold the pattern inside parantheses
  6.       } }
  7.  
May 14 '08 #2
nithinpes
410 Expert 256MB
The title of your post doesn't match your description. If you actually wanted to match begining and end of a line, here is how to do it.
The symbol '^' will denote beginning of line/string inside pattern match. For ex:
/^The/ will match only the lines begining with 'The'.

Similarly, the symbol '$' will denote end of line/string inside pattern match. For ex:
/end$/ will match only the lines ending with 'end'.
May 14 '08 #3
poolboi
170 100+
hm...thanks nithinpes

i might need the code for beginning and end of statements

i guess for this case it should somehow be match a part of a sentence ending with special characters like "*", "%", and stuff

anyway if i use ".*" it matches 1 character 0 or more times right?
and ".+" it matches 1 character 1 or more times right?
May 15 '08 #4
nithinpes
410 Expert 256MB
hm...thanks nithinpes

i might need the code for beginning and end of statements

i guess for this case it should somehow be match a part of a sentence ending with special characters like "*", "%", and stuff

anyway if i use ".*" it matches 1 character 0 or more times right?
and ".+" it matches 1 character 1 or more times right?
Yes. That's right!
One way of matching special characters is to escape them(using '\'). For example in your text, if you wanted to match lines with '/* 4' you could use,
Expand|Select|Wrap|Line Numbers
  1. if ($data1 =~ /\/\* 4/) { 
  2.  
Also, you could use \Q and \E. \Q will remove any special meaning, inside pattern match, of the characters that follow it upto \E.
For ex:
Expand|Select|Wrap|Line Numbers
  1. if ($data1 =~ /\Q/* @+/\E/) { # will match '/* @+/'
  2. if ($data1 =~ /\Q/* ...\E.+/) {# will match '/* ...' followed by one/more characters
  3.  
I would suggest you to go through this:
Perl RE

-Nithin
May 15 '08 #5
poolboi
170 100+
alright
thanks you very much nithin
was looking for some reference too
thanks!
cheers, :)
May 15 '08 #6
poolboi
170 100+
hey guys another question to ponder about

how long u think it takes to do a search on my code below
roughly around 2,375 KB of data

Expand|Select|Wrap|Line Numbers
  1. foreach $data1 (@data)
  2. {
  3. chomp ($data1); 
  4.  
  5. if ($data1 =~ /3 SESSION/ && $data1 !~ /2 TBHLR/ && $data1 !~ /1 TBHLR/ && $data1 !~ /4c COMMAND/ && $data1 !~ /4c 
  6. SESSION/){
  7.  
  8. my $user_line = index ($data1, "3 SESSION");
  9. my $user = substr ($data1, ($user_line+23),6);
  10. push @array1,$user;
  11.  
  12. my $time_line = index ($data1, "USERID");
  13. my $time = substr ($data1, ($time_line+25),8); 
  14. push @array2,"$time\n";
  15.  
  16. push @array3, "$date\n";
  17.  
  18. }elsif
  19. ($data1 =~ /4 (\D\D\D:.+)\*/){
  20. push @array4, "$1\n";
  21.  
  22. }}
  23.  
and all these datas are added into MySQL database
i time it and ard 5-6 mins
u think it's already considered fast?
May 15 '08 #7

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

Similar topics

1
by: redryderridesagain | last post by:
Using the Microsoft VBScript Regular Expressions 5.5 library in MS-Access VBA 6.3. I understand why the code below finds an occurance of the string "PC: blah blah blah A: BBB aaa B: BBB bbb C:...
11
by: TokyoJ | last post by:
I run a small camp in Alaska for kids and my director is asking for a web form. Could someone please have a look and offer some advice on where I'm making mistake(s)? I'm using the RegExp function...
4
by: s99999999s2003 | last post by:
hi how can i use regexp to group these digits into groups of 3? eg line 123456789123456789 i have : pat = re.compile("line\s+(\d{3})" , re.M|re.DOTALL)
2
by: Papkin | last post by:
Hi if ( eregi("^/a-zA-Z0-9±ęćłń󶿼ˇĆĘŁŃÓ¦¬Ż\.\/\/-]{2,65}$","Merry & Cat") ) return true; else return false; I'd like to match also "&" but this regexp above does not do...
2
by: richardkreidl | last post by:
I have the following string below in which I need to pull out the name that follows: ContactsManager:" . In this particular case it would be: BARBARA JOSEPH Job Completion, Failure...
4
by: Ciaran | last post by:
Hi can someone give me hand with this please? What's the best way to extract the extension from the url? example: $string="http://www.domain.co.uk/anypage.html" In this example, I'd be...
4
by: TobbeK | last post by:
Anyone having experience in MySQL and REGEXP ? I have 1 input field, "what" Let's say I have the input value "e-mail" and the database field contains the value "email". Is there some way to put...
7
by: poolboi | last post by:
hey guys, another regexp problem which i'm probably not good at here goes my text file has this /* 1 TB VTP-1 SESSION=01547 USERID STARTED 2008-05-13 09:46:11 */ I AM A GIRL /* 3...
4
by: Velhari | last post by:
Hi all, I wrote the following Javascript function used to execute the Javascript codes from the ajax response which contains both html & javascript. It works fine, if the javascript codes from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
0
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 projectplanning, coding, testing,...

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.