Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi monk, I have a string which contains data of a person delimited by '%'. The third field in the string represents 'ID' tag, I want to extract all thr names which has ID tag starting with 'A'. For example $data variable may contain :

$data = "Johnson%Andrew%AX321%Engineer" ; $data = "Smith%John%BC142%Alberta";

I am using :

print "$2 $1\n" if m/^(.*?)%(.*?)%A/;

But this is giving me

Andrew Johnson ## output Ok John%BC142Smith ## Wrong

But I don't want this. The second half of the regex does not say match up to next % and then match 'A'. Instead it says match upto the next % which is followed by 'A'. Hence for the second $data it is getting past the second % and fetching John%BC142Smith Please help. Thanks.


In reply to Regex help needed by ghosh123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 22:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found