I am trying to display only the line that ends with a . or , or ? that has the in the line that ended with .|,|?
So here is my pattern-matching operator:
m/the/ .. /(\.|\?|\,)$/im
I am not sure if that is the correct pattern to look for, but if it is how do I extract just what matches that?
For example if I had
I wish it was the that dog barked,
but it wasn't.
It was a cat.
I need to only print "the dog barked,"
5 1183
keirnna,
What you have done here is correct /(\.|\,|\?)$/im.
But i am not sure what you are doing here (/the/../).
You can also use the character class to accomplish the same:
/([.,?])$/im
Regards,
Prasad
I hope this might help you,
Example:
use strict;
use warnings;
my $string = "I wish it was the that dog barked,
but it wasn't.
It was a cat?";
while ($string =~ m/([.\,?])$/gim) {
print "line ended with <$1>\n";
}
miller 1,089
Recognized Expert Top Contributor
Or if you want exactly what you stated: -
my $string = "I wish it was the dog that barked,\nbut it wasn't.\nIt was a cat?";
-
-
while ($string =~ m/(the.*?[.,?])$/gim) {
-
print "line ended with <$1>\n";
-
}
-
# Outputs: line ended with <the dog that barked,>
-
KevinADC 4,059
Recognized Expert Specialist
Hi Miller,
Seems we have been working on the same question, allbeit on different forums: -
my $file = $ARGV[0];
-
-
open(INPUT, $file)
-
or die "Couldn't open $file for reading: $!\n";
-
-
while (<INPUT>) {
-
if (m/(it.*[?,.])$/i) {
-
print "$1\n";
-
}
-
}
-
close(INPUT);
-
(from other forum)
Here is the file I want to scan:
Tim created the Module List in August 1994 and maintained it manually till
April 1996. By that time Andreas had implemented the Perl Authors Upload
Server (PAUSE) and it was happily feeding modules through to the CPAN archive sites.
Since PAUSE held a database of module information which could be maintained by module authors
it made sense for the module listing part of the Module List to be built
from that database. In April 1996 Andreas took over the automatic posting of
the Module List and I now maintain the other parts of the text. We plan to add
value to the automation over time.
Yes I also posted on another forum. I don't see what the problem is. Thanks for the help so far.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dean A. Hoover |
last post by:
I've got a 4 line message that looks like this:
Encountered "<EOF>" at line 1, column 7.
Was expecting one of:
"=" ...
"]]" ...
and want to get the line and column numbers
from it. This is...
|
by: Kelmen Wong |
last post by:
Greeting,
I want to extract all "" from a string, what pattern should I
used?
eg.
=
- return array or test1, or test2
|
by: aevans1108 |
last post by:
expanding this message to microsoft.public.dotnet.xml
Greetings
Please direct me to the right group if this is an inappropriate place
to post this question. Thanks.
I want to format a...
|
by: Ed Brown |
last post by:
I'm working on a VB.Net application that needs to do quite a bit of string
pattern matching, and am having problems using the "LIKE" operator to match
the same string twice in the pattern. For...
|
by: shonend |
last post by:
I am trying to extract the pattern like this :
"SUB: some text LOT: one-word"
Described, "SUB" and "LOT" are key words; I want those words,
everything in between and one word following the...
| |
by: mehdi_mousavi |
last post by:
Hi folks,
Consider the following JavaScript function:
function removeParam(str, name)
{
var rgx = new RegExp('(' + name + '=\\w*)|(' + name + '=\\w*;)');
rgx.global = true;
rgx.ignoreCase =...
|
by: konrad Krupa |
last post by:
I'm not expert in Pattern Matching and it would take me a while to come up
with the syntax for what I'm trying to do.
I hope there are some experts that can help me.
I'm trying to match...
|
by: mosesdinakaran |
last post by:
Can any one explain how the rule is applied for the following Regular
expression
$Str = 'the red king';
$Pattern = '/((red|white) (king|queen))/';
preg_match($Pattern,$Str,$Val);
Result:
|
by: eBob.com |
last post by:
Is there a regex pattern which will match a VB.Net string? I.E. a regex
which matches ...
"this is a ""vb.net"" string"
(I don't want three matches in this case, I want one.) I've come up...
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |