Re: Extract part of a string



On Apr 30, 2:47 pm, roopa...@xxxxxxxxx wrote:
On Apr 30, 9:53 am, Paul Lalli <mri...@xxxxxxxxx> wrote:





On Apr 30, 9:21 am, roopa...@xxxxxxxxx wrote:

Hi,

I want to extract everything between the hash signs in the following
string

"### This is a test ###"

I am using the following..

if($desc=~ /\#{3}(.*?)\#{3}/ )
{
print $1;

}

I am not getting the desired result. Please tell me what I am doing
wrong.

What you're doing wrong is not posting a short-but complete script
that demonstrates your error. Because what you have above *does*
work. So therefore you're doing something wrong in your actual code
that you haven't bothered to show us...

$ perl -e'
my $desc = "### This is a test ###";
if($desc=~ /\#{3}(.*?)\#{3}/ )
{
print $1;}

'
Results: This is a test

Paul Lalli- Hide quoted text -

- Show quoted text -

My String contains new line characters like
"This is a test

BEGIN PART INFORMATION##
5G5E-6010-AA|BLK ASY-CYL|
##END PART INFORMATION

"

And apparently your string also has only 2 # characters bunched
together, not three?

What part of "post a short but complete script" was too difficult to
follow? Why are you making me *guess* what other differences might be
in your real code, that you didn't feel like sharing with us? You're
being very rude to those people who are volunteering their time trying
to help you.

Read `perldoc perlretut` and `perldoc perlre`.

You need the /s modifier on your regexp to allow the . wildcard to
match newlines.

Paul Lalli

.



Relevant Pages

  • Re: I need help
    ... fscanfwith the "%s" option reads a white-space delimited string. ... You must check the result of the fscanf() function. ... This isn't your real code, ... If you want to return an int, ...
    (comp.lang.c)
  • Re: how to change decimal symbol in VB / Access?
    ... PS> that's right TIM, some of the code wasn't real, becouse the real code is ... > string and double has a lower case letters, so I assume that this is not ... the backslash forces the use of a dot rather than whatever OLEAUT32 ...
    (microsoft.public.access.modulesdaovba)
  • Re: Problem with xsl to make a text control disabled
    ... It would help if you gave us a stand-alone runnable example that provokes the problem, rather than a fragment. ... maybe comparing it with your real code will help you figure out what you're doing wrong. ... Second case: The string has been set to [<xsl:value-of ...
    (comp.text.xml)
  • Re: Extract part of a string
    ... And apparently your string also has only 2 # characters bunched ... being very rude to those people who are volunteering their time trying ... Read `perldoc perlretut` and `perldoc perlre`. ...
    (perl.beginners)
  • Re: Subform wont sort properly
    ... Assuming that this is a copy/paste of your real code: ... It opens sorting another field located on the form. ... > Dim MySQL As String, MyCriteria As String, MyRecordSource As String ...
    (microsoft.public.access.queries)