Professional Web Applications Themes

Regex search question - PERL Beginners

I know that if ( /VALUE={1}(\d+)/ ) { looks for the first occurrence of value. How do I find the last occurrence? --Paul...

Sponsored Links
  1. #1

    Default Regex search question

    I know that

    if ( /VALUE={1}(\d+)/ ) {

    looks for the first occurrence of value. How do I find the last occurrence?

    --Paul

    Sponsored Links
    Paul Harwood Guest

  2. #2

    Default Re: Regex search question

    Paul Harwood wrote:
    >
    > I know that
    >
    > if ( /VALUE={1}(\d+)/ ) {
    >
    > looks for the first occurrence of value. How do I
    > find the last occurrence?
    Firstly you don't need the {1} in there. All it's
    doing is insisting that there is only one equals
    character, which an unquantified /=/ will do anyway.

    To find the last occurrence, just chew up as many
    characters as possible from the object string first:

    /.*VALUE=(\d+)/

    HTH,

    Rob


    Rob Dixon Guest

  3. #3

    Default Re: Regex search question

    Paul Harwood wrote:
    >
    > I know that
    >
    > if ( /VALUE={1}(\d+)/ ) {
    >
    > looks for the first occurrence of value. How do I find the last occurrence?
    Probably the most efficient way:

    my $rev = reverse $_;
    if ( $rev =~ /(\d+)=EULAV/ ) {


    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn Guest

  4. #4

    Default Re: Regex search question

    On Nov 6, John W. Krahn said:
    >Paul Harwood wrote:
    >>
    >> if ( /VALUE={1}(\d+)/ ) {
    >>
    >> looks for the first occurrence of value. How do I find the last occurrence?
    >
    >Probably the most efficient way:
    >
    >my $rev = reverse $_;
    >if ( $rev =~ /(\d+)=EULAV/ ) {
    Remember to reverse $1, though. You could also do

    /.*VALUE=(\d+)/

    --
    Jeff "japhy" Pinyan [email]japhypobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
    RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
    <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
    [ I'm looking for programming work. If you like my work, let me know. ]

    Jeff 'Japhy' Pinyan Guest

Similar Threads

  1. regex question
    By Math55 in forum PERL Beginners
    Replies: 19
    Last Post: July 21st, 06:22 PM
  2. search and replace using regex
    By Tom Kinzer in forum PERL Beginners
    Replies: 5
    Last Post: December 6th, 03:40 AM
  3. Regex search using scalar
    By Paul Harwood in forum PERL Beginners
    Replies: 5
    Last Post: November 6th, 11:54 AM
  4. Simple regex question
    By Gunnar Hjalmarsson in forum PHP Development
    Replies: 9
    Last Post: August 15th, 12:35 AM
  5. Regex question...
    By Greg Bacon in forum PERL Miscellaneous
    Replies: 1
    Last Post: July 15th, 09:21 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139