Professional Web Applications Themes

regex question - PERL Beginners

hi, the regex .* should match everything but newline, right? but it doesnt. sime time ago i read something that .* will not match evrything? is that true? THANKS......

  1. #1

    Default Regex question

    hi, the regex .* should match everything but newline, right? but it
    doesnt. sime time ago i read something that .* will not match
    evrything? is that true?

    THANKS...
    Math55 Guest

  2. #2

    Default Re: Regex question

    Math55 wrote:
    > hi, the regex .* should match everything but newline, right?
    Correct.
    > but it
    > doesnt.
    Give specifics of when you observed that it did not.

    Chris Mattern

    Chris Mattern Guest

  3. #3

    Default Re: Regex question

    Math55 <magelordt-online.de> wrote:
    > the regex .* should match everything but newline, right? but it
    > doesnt.

    Yes it does.

    Show us code where it doesn't.


    --
    Tad McClellan SGML consulting
    [email]tadmcaugustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  4. #4

    Default regex question

    Hi,

    When I run my program with "use warnings". I get the following error:

    Use of uninitialized value in concatenation (.) or string at
    miva_order_check.pl
    line 52, <ORDER> line 40067.

    Here is the is offending line of code:

    my $sth =$dbh->prepare("UPDATE miva_orders SET
    shiptype='$shipping_method',coupon_type='$coupon_t ype',coupon_amount='$coupo
    n_amount' WHERE order_number='$order_number'");

    What do I need to do to fix this?

    TIA

    Trevor

    Trevor Morrison Guest

  5. #5

    Default Re: regex question


    --On Sunday, August 10, 2003 7:19 AM -0600 Trevor Morrison
    <demohailix.com> wrote:
    > When I run my program with "use warnings". I get the following error:
    >
    > Use of uninitialized value in concatenation (.) or string at
    > miva_order_check.pl
    > line 52, <ORDER> line 40067.
    >
    > Here is the is offending line of code:
    >
    > my $sth =$dbh->prepare("UPDATE miva_orders SET
    > shiptype='$shipping_method',coupon_type='$coupon_t ype',coupon_amount=
    > '$coupon_amount' WHERE order_number='$order_number'");
    >
    > What do I need to do to fix this?
    I see no regex here.

    As the warning says, one of your variables doesn't contain a value (is
    uninitialized). Maybe you somehow missed assigning a value, pd the
    ORDER file incorrectly, or the data is missing from the ORDER file, or ....
    If the data is missing from the ORDER file, you need to add code to check
    for this and decide how to handle it.

    --
    David Wall

    David Wall Guest

  6. #6

    Default Regex Question


    Got a pretty simple question for you'all. This matches the
    number data shown below:

    foreach (<DATA>) {
    /^.+\s(\d+.\d+),\s-(\d+.\d+),.*$/;
    print "$1 -- $2 \n";
    push array, $1, $2;
    }

    Now, just in case the single space is not before the numbers
    like those shown below in DATA, I thought I'd put in a "?"
    after the \s, and make it:
    /^.+\s?(\d+.\d+),\s?-(\d+.\d+),.*$/;
    it returns the $2 OK, but the $1 is only the last 3 digits of what
    I expect. I expect
    35.020041249 -- 94.3847918870
    and get
    249 -- 94.3847918870

    What am I missing here?


    __DATA__
    TP,DMS, 35.020041249, -94.3847918870,12/31/1989,00:00:00,1
    TP,DMS, 35.010973698, -94.3846837580,12/31/1989,00:00:00,0
    TP,DMS, 35.002423715, -94.3837645520,12/31/1989,00:00:00,0
    TP,DMS, 34.595735442, -94.3845292880,12/31/1989,00:00:00,0
    TP,DMS, 34.594175007, -94.3845061190,12/31/1989,00:00:00,0
    TP,DMS, 34.585702269, -94.3817021280,12/31/1989,00:00:00,0
    TP,DMS, 34.575576402, -94.3814240620,12/31/1989,00:00:00,0
    TP,DMS, 34.571204088, -94.3744192330,12/31/1989,00:00:00,0
    TP,DMS, 34.561611241, -94.3742261350,12/31/1989,00:00:00,0
    TP,DMS, 34.554861166, -94.3737394970,12/31/1989,00:00:00,0
    TP,DMS, 34.552041565, -94.3726348980,12/31/1989,00:00:00,0
    TP,DMS, 34.545121539, -94.3707114980,12/31/1989,00:00:00,0
    TP,DMS, 34.544642592, -94.3654524020,12/31/1989,00:00:00,0

    Mike Flannigan Guest

  7. #7

    Default Re: Regex Question

    On Sun, 17 Aug 2003 19:40:52 GMT, Mike Flannigan <mikeflanearthlink.net> wrote:
    >
    > Got a pretty simple question for you'all. This matches the
    > number data shown below:
    >
    > foreach (<DATA>) {
    > /^.+\s(\d+.\d+),\s-(\d+.\d+),.*$/;
    > print "$1 -- $2 \n";
    > push array, $1, $2;
    > }
    >
    A couple of comments:

    1. you're not checking that the regexp matched before using $1, $2
    2. (\d+.\d+) doesn't match what I think you think it matches--maybe
    you mean "(\d+\.\d+)"?
    3. how about just split()ting this nice comma-delimited data?

    my ($lat,$lon) = (split /,/, $_)[2,3]; # untested

    4. The problem with adding the '?' to \s is that the space
    was the only thing keeping the .+ from greedy-matching the
    first part of your latitude.

    John J. Trammell Guest

  8. #8

    Default Re: Regex Question

    Mike Flannigan <mikeflanearthlink.net> wrote:
    >
    > Got a pretty simple question for you'all. This matches

    [ snip m// ]

    > What am I missing here?

    unpack() is useful with fixed width fields.

    > TP,DMS, 35.020041249, -94.3847918870,12/31/1989,00:00:00,1

    my( undef, $num1, undef, $num2 ) = unpack 'A8 A12 A3 A13', $_;


    --
    Tad McClellan SGML consulting
    [email]tadmcaugustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  9. #9

    Default Re: Regex Question

    Mike Flannigan wrote:

    (snipped a lot)

    Others have provided good advice on your regex method.

    I am puzzled why you don't simply use "zero or more"
    regex match spaces for your "between numbers" parameter.
    > I expect35.020041249 -- 94.3847918870
    > and get
    > 249 -- 94.3847918870
    Where is this extra hypen being generated?

    > What am I missing here?
    > __DATA__
    > TP,DMS, 35.020041249, -94.3847918870,12/31/1989,00:00:00,1

    What you are missing is to use substring for fixed
    length data. All your data displayed is of equal length.
    You will find substring to be more efficient for this
    type of data than a regex method, making a presumption
    your data is truly fixed length. Transliteration or
    substitution can be used to remove a single comma captured.


    Purl Gurl
    Purl Gurl Guest

  10. #10

    Default Re: Regex Question

    >>>>> "PG" == Purl Gurl <purlgurlpurlgurl.net> writes:
    >> 249 -- 94.3847918870
    PG> Where is this extra hypen being generated?

    print "$1 -- $2 \n";
    >> What am I missing here?
    your brain as usual.


    uri

    --
    Uri Guttman ------ [email]uristemsystems.com[/email] -------- [url]http://www.stemsystems.com[/url]
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- [url]http://jobs.perl.org[/url]
    Uri Guttman Guest

  11. #11

    Default Re: Regex Question


    Tad McClellan wrote:
    > unpack() is useful with fixed width fields.
    >
    > > TP,DMS, 35.020041249, -94.3847918870,12/31/1989,00:00:00,1
    >
    > my( undef, $num1, undef, $num2 ) = unpack 'A8 A12 A3 A13', $_;
    That is useful. Thanks for the pointer.
    Pack and Unpack is something that is often overlooked by me
    in favor of regex's. Not sure that will change, but these
    functions appear very good for fixed width formats.


    Mike


    Mike Flannigan Guest

  12. #12

    Default Re: Regex Question



    Purl Gurl wrote:
    > #!perl
    >
    > while (<DATA>)
    > {
    > ($num_1, $num_2) = split (/,[ ]*-/, substr ($_, 8, 28));
    > $num_2 =~ tr/,//d;
    > print "$num_1 -- $num_2\n";
    > }
    >
    > __DATA__
    > TP,DMS, 35.020041249,-94.3847918870,12/31/1989,00:00:00,1
    > TP,DMS, 35.010973698, -94.3846837580,12/31/1989,00:00:00,0
    > TP,DMS, 35.002423715,-94.3837645520,12/31/1989,00:00:00,0
    > TP,DMS, 34.595735442, -94.3845292880,12/31/1989,00:00:00,0
    >
    > PRINTED RESULTS:
    > ________________
    >
    > 35.020041249 -- 94.3847918870
    > 35.010973698 -- 94.3846837580
    > 35.002423715 -- 94.3837645520
    > 34.595735442 -- 94.3845292880
    Pretty cool. I didn't know you could put an optional [] in
    a split command, along with a quantifier like *. How
    interesting (and dangerous). Here is a key line I bypassed:

    "The delimiters are determined by repeated pattern matching,
    using regular expressions given in pattern, so the delimiters
    may be of any size and need not be the same string on
    every match."

    Very interesting.

    Mike Flannigan Guest

  13. Moderated Post

    Default Re: Regex Question

    Removed by Administrator
    Purl Gurl Guest
    Moderated Post

  14. #14

    Default regex question

    Howdy:

    Is it possible to use regex to replace
    the first n characters of a line?
    There are no unique markers or items
    to map by in these files ... some lines could
    start with number or whatever (special
    characters, white space, alpha, etc).

    If so, how?

    Thanks!

    -X

    Shaunn Johnson Guest

  15. #15

    Default Re: regex question

    On Friday, September 12, 2003, at 10:41 AM, Johnson, Shaunn wrote:
    > Howdy:
    >
    > Is it possible to use regex to replace
    > the first n characters of a line?
    > There are no unique markers or items
    > to map by in these files ... some lines could
    > start with number or whatever (special
    > characters, white space, alpha, etc).
    >
    > If so, how?
    Yes, but use substr() instead.

    perldoc -f substr

    James

    James Edward Gray II Guest

  16. #16

    Default Re: RegEx Question

    Hi Roy,

    --- Original Message
    From: Zysman, Roiy <com>
    Date: Sunday, July 18, 2004 at 01:14AM PDT

    ZR> Is there a way to extract a filename out of a path string using just one
    ZR> RegEx and not using the split function ?

    ZR> For Example, I want to extract foo.txt from /my/long/path/foo.txt path
    ZR> string.

    I found this cool trick a while ago and it works nicely.

    my($directory, $filename) = $text =~ m/(.*\/)(.*)$/;
    print "D=$directory, F=$filename\n";

    -MikeD

    Mike Guest

  17. #17

    Default Re: RegEx Question

    From: Mike Dillinger <com> 

    It does? Let me try:

    my xt = 'c:\soft\wscite\scite.exe';
    my($directory, $filename) = $text =~ m/(.*\/)(.*)$/;
    print "D=$directory, F=$filename\n";
     [/ref]

    The delimiter depends on the OS, Unixes use /, Windows use \ (but
    accepts / on most places as well), Macintoshes (at least the old
    ones) use :. And then there is VMS.

    If you want to be portable use a module.

    Jenda
    ===== cz === http://Jenda.Krynicky.cz =====
    When it comes to wine, women and song, wizards are allowed
    to get drunk and croon as much as they like.
    -- Terry Pratchett in Sourcery

    Jenda Guest

  18. #18

    Default Regex question

    How can I control if "a textbox is empty or not" with regex validation? I
    don't want to use required field validator because I have a masked textbox
    control and it has "ValidationExpress" property.
    For example, if I want to control if it's a time value, I use
    "(([0-1][0-9])|([2][0-3]))[:]([0-5][0-9])" but it doesn't work when textbox
    is empty. How can I solve this problem? I want user to fill this area.
    And by the way, if I try to use a req field validator for this, my masked
    textbox doesn't seem on validator's "Control To Validate" property although
    it has been inherited from textbox control.


    Waiting for your replies.

    Sincerely


    Hailstorm Guest

  19. #19

    Default Re: Regex question

    I ran into this problem myself -- the validator does not check empty fields
    (see below). I ended up inheriting the validator and changing the
    client-side javascript to include my own validation function. The downside
    is that I had to add that function to a custom WebUIValidation.js (ugh).

    One thing you could do is do the validation on the postback, and then
    trigger the validator (validator.IsValid = false).


    Hope this helps,
    Sam Fields

    excerpt from WebUIValidation.js ...

    function RegularExpressionValidatorEvaluateIsValid(val) {
    var value = ValidatorGetValue(val.controltovalidate);

    #### if length=0 arbitrary "yes" #####
    if (ValidatorTrim(value).length == 0)
    return true;
    var rx = new RegExp(val.validationexpression);
    var matches = rx.exec(value);
    return (matches != null && value == matches[0]);
    }


    "Hailstorm" <nomail> wrote in message
    news:%23UgGX3nhEHA.636TK2MSFTNGP12.phx.gbl...
    > How can I control if "a textbox is empty or not" with regex validation? I
    > don't want to use required field validator because I have a masked textbox
    > control and it has "ValidationExpress" property.
    > For example, if I want to control if it's a time value, I use
    > "(([0-1][0-9])|([2][0-3]))[:]([0-5][0-9])" but it doesn't work when
    textbox
    > is empty. How can I solve this problem? I want user to fill this area.
    > And by the way, if I try to use a req field validator for this, my masked
    > textbox doesn't seem on validator's "Control To Validate" property
    although
    > it has been inherited from textbox control.
    >
    >
    > Waiting for your replies.
    >
    > Sincerely
    >
    >

    news.microsoft.com Guest

  20. #20

    Default Re: Regex question

    If you would rather get a regex validator that already has the ability to
    support blank textboxes instead of writing the code yourself, I can offer a
    solution.
    I rewrote ASP.NET validation to address all kinds of limitations including
    this one. "Professional Validation And More"
    ([url]http://www.peterblum.com/vam/home.aspx[/url]) includes 22 validators. Its
    RegexValidator has a property to allow blank text. All of these validators
    support client side validation on many more browsers than the original
    validators which are limited to DHTML browsers.

    Even if you don't want a third party solution, you may benefit from knowing
    the limitations to ASP.NET validation as you plan your site. I put together
    a list: [url]http://www.peterblum.com/vam/valmain.aspx[/url].

    --- Peter Blum
    [url]www.PeterBlum.com[/url]
    Email: [email]PLBlumPeterBlum.com[/email]
    Creator of "Professional Validation And More" at
    [url]http://www.peterblum.com/vam/home.aspx[/url]


    "Hailstorm" <nomail> wrote in message
    news:%23UgGX3nhEHA.636TK2MSFTNGP12.phx.gbl...
    > How can I control if "a textbox is empty or not" with regex validation? I
    > don't want to use required field validator because I have a masked textbox
    > control and it has "ValidationExpress" property.
    > For example, if I want to control if it's a time value, I use
    > "(([0-1][0-9])|([2][0-3]))[:]([0-5][0-9])" but it doesn't work when
    textbox
    > is empty. How can I solve this problem? I want user to fill this area.
    > And by the way, if I try to use a req field validator for this, my masked
    > textbox doesn't seem on validator's "Control To Validate" property
    although
    > it has been inherited from textbox control.
    >
    >
    > Waiting for your replies.
    >
    > Sincerely
    >
    >

    Peter Blum Guest

Similar Threads

  1. Maybe Stupid RegEx Question
    By Bastian Angerstein in forum PERL Beginners
    Replies: 2
    Last Post: February 13th, 03:14 PM
  2. Regex search question
    By Paul Harwood in forum PERL Beginners
    Replies: 3
    Last Post: November 7th, 04:52 AM
  3. A small regex question
    By Online in forum PHP Development
    Replies: 3
    Last Post: October 30th, 09:22 AM
  4. perl regex question
    By Chad Williams in forum PERL Miscellaneous
    Replies: 7
    Last Post: September 11th, 07:04 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