Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

i wann get some character from a string

by weihe (Initiate)
on Aug 02, 2006 at 03:18 UTC ( [id://565133]=perlquestion: print w/replies, xml ) Need Help??

weihe has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: i wann get some character from a string
by GrandFather (Saint) on Aug 02, 2006 at 03:32 UTC
Re: i wann get some character from a string
by McDarren (Abbot) on Aug 02, 2006 at 03:33 UTC
    "..how can i write a regular expressions for this .."

    If you wish to learn about regular expressions, then probably the two best places to start are with perlre and perlretut.

    If you are really serious about learning regular expressions, then you'll be wanting a copy of the Owl.

    Cheers,
    Darren

      thanks for your advise me, i will follow you to learnning regular expressions
Re: i wann get some character from a string
by GhodMode (Pilgrim) on Aug 02, 2006 at 03:44 UTC

    If you really want to use a regular expression for this, it would be something like /^.*?=(.*)$/. After that regex, $1 would hold your ID.

    A regular expression isn't the right tool for that. Regular expressions can be expensive in terms of efficiency. So, you should favor other methods when possible.

    For those strings use split ...

    use strict; use warnings; my @strings = ( "http://mysite/bbsui.jsp?id=dxpwd", "http://mysite/bbsui.jsp?id=dxpsf", "http://mysite/bbsui.jsp?id=sfpwd", "http://mysite/bbsui.jsp?id=ds35e", "http://mysite/bbsui.jsp?id=124536" ); for ( @strings ) { my ($base, $id) = split( /=/, $_, 2 ); print "Id: $id\n"; }

    --
    -- Ghodmode
    
    Blessed is he who has found his work; let him ask no other blessedness.
    -- Thomas Carlyle
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: i wann get some character from a string
by planetscape (Chancellor) on Aug 02, 2006 at 17:53 UTC
Re: i wann get some character from a string
by Lidskjalv (Novice) on Aug 02, 2006 at 18:51 UTC
    My understanding is that you want ids as a comma separated list, for all ids used as the suffix to the one and only prefix as in $base below. I have added two strings to the collection in order to filter out strings of no interest to you. Try this code:
    use strict; use warnings; my @strings = ( "http://mysite/bbsui.jsp?id=dxpwd", "http://mysite/bbsui.jsp?id=dxpsf", "http://mysite/bbsui.jsp?id=sfpwd", "http://somewhere.else.jsp?id=YOU-DO-NOT-WANT-THIS", "http://mysite/bbsui.jsp?id=ds35e", "http://somewhere.else.too?id=XXXXXXXXXXXXXXXXXXXX", "http://mysite/bbsui.jsp?id=124536" ); my $base = 'http://mysite/bbsui.jsp?id='; my $pattern = "^\Q$base\E(.+)\$"; my @id = grep { $_ } map { $1 if /$pattern/ } @strings; print "(" . join (',', @id) .")\n";
    Prints the requested output:
    (dxpwd,dxpsf,sfpwd,ds35e,124536)
      thanks very much
Re: i wann get some character from a string
by jesuashok (Curate) on Aug 02, 2006 at 03:24 UTC
    Hi

    Is that ur home work ?

    update ..

    use strict; use warnings; my @strings = ( "http://mysite/bbsui.jsp?id=dxpwd", "http://mysite/bbsui.jsp?id=dxpsf", "http://mysite/bbsui.jsp?id=sfpwd", "http://mysite/bbsui.jsp?id=ds35e", "http://mysite/bbsui.jsp?id=124536" ); for ( @strings ) { my ($id) = split( /=/, $_)[1]; print "Id: $id\n"; }
    or
    $xyz = "http://mysite/bbsui.jsp?id=dxpwd"; $id = $1 if ($xyz =~ m/\?id=(.+?)$/i);

    "Keep pouring your ideas"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://565133]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found