|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
Regular expression in Perl Hi I am trying to write a regular expression in perl that will match the first letter / character of a string and the last letter / character of the string. I have this statement for my expression. Code: if ($string =~ m/(^([a-z]+\s*)+$)/) Code: #!/usr/bin/perl while () { print "enter something: \n"; chomp ($string =<STDIN>); if ($string =~ m/(^([a-z]+\s*)+$)/) { print "Found letter '$1' was found ", pos($text), " \n"; print "This string begins and ends with same character with \n"; last; } else { print "This string does not begin and end with the same character \n"; } |
#2
| |||
| |||
Re: Regular expression in Perl Hello Are you trying to test a given string starts and ends with the same character? I just want to be sure that I have understood your problem correctly. If this is the case, I have tried it in two way. Find out what the first letter is and insert it into a variable, then find out what the last letter is and put it into another variable. And then you have to compare the tow strings. In this case there is no need of a regular expression. In general you have to first extract the first and the last letters. then construct your regular expression dynamically. and finally do the match. |
#3
| |||
| |||
Re: Regular expression in Perl Hi Thanks for replying I have used the following statement in my code. Code: if ($string =~ m/^(.+)+(.+)\1$/) This string begins and ends with same character with 2) If the end is near This string does not begin and end with the same character The problem is that it will only check one way, I need it to check both ways. Do you have any suggestions |
![]() |
|
Tags: perl, programming language, regular expression |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Using Regular Expression than Substring in Microsoft Excel | Jigisha | MS Office Support | 5 | 25-01-2012 06:19 PM |
Regular expression Help in asp.net for DOB. | maheshmartha | Software Development | 2 | 06-03-2010 07:06 AM |
Regular expression in MySQL | Fragman | Software Development | 4 | 02-03-2010 10:15 PM |
why to use * at the start of a C expression? | Nadiaa | Software Development | 4 | 10-02-2010 10:57 PM |
Convert php expression | SoftWore | Software Development | 3 | 05-12-2009 02:21 PM |