Dear Monks,
I am new to PERL and hope you can help me with a regex question.
What I want is to find the largest integer in each string. The following are two example of the strings that I am currenly working on:
ASBSDEC 34 GADVVEEVEETTE 56 IOEOREAK GKJEOG EFEAF 1090 DAFFEE 376
ASB C 134 PPKOREAK EFEAF 290
So, I want the number 1090 for the first string, 290 for the second. As I got thousands of such strings, I don't know how many integers there are in each string (some string could be extremely long with more than 100 integers in it.
I wonder if there is any way to read the integers one by one: get first integer as $var, then go to the second integer and compare that with $var, if larger then replace $var, otherwise, go ahead with the third integer, repeat until the last integer in the string.
I tried some thing like /\d+?/g, but it does not seem to be working. :(
I really appreciate it if you can help me out here.
BTW, to be a bit more complex, is there any way I can get the text before each integer using $'?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.