Regular Expression help please

Discussion in 'Perl Misc' started by Shane, Oct 5, 2004.

  1. Shane

    Shane Guest

    Hi,

    I'm sure this message doesn't belong here exactly, but I know all the
    Perl gurus know regular expressions really well and I can't find a
    group just for regular expressions.

    Anyway, I am trying to use regular expressions to find patterns and
    add to them - not replace.

    Specifically, I want to find something like:

    foo?4567"

    and replace it with something like:

    foo?4567.txt"

    I really don't want to write a perl script to do it - I thought I
    could do it in textpad or vi, but I'm having trouble with the syntax.
    In Perl I would just find foo?.*\" and use $1 as the variable to
    replace the number to the original number. For some reason, I can't
    get textpad to do what I want and I'm sure I'm just missing something
    simple.

    Thanks in advance for the help, and not flaming me. Although if this
    really needs to be about Perl, I'll take corrections on my assumptions
    about how to do it in Perl and just write a script to do it. It just
    seems overkill.

    shane
     
    Shane, Oct 5, 2004
    #1
    1. Advertisements

  2. (Shane) wrote in
    You might want to head on over to comp.editors for help with text editors.

    Sinan.
     
    A. Sinan Unur, Oct 5, 2004
    #2
    1. Advertisements


  3. perl -p -i~ -e 's/(foo\?[^"]+)"/$1.txt"/g' file
     
    Tad McClellan, Oct 5, 2004
    #3
  4. Shane

    ZafT Guest

    First of all, you don't have to read the frickin post. I tried to ask
    nicely, as I didn't know where elso to go, and groveled at the group's feet
    for mercy to avoid getting flamed.

    Second, how much of a bother is it to post a message. Hundreds? I think
    not. If so, then you just bothered the same group of people by posting a
    reply- a senseless one I might add. At least I really needed some help.
    Now I just had to bother them all over again just to bitch at you.

    Third, i just didn't have a perl interpreter (and can't install one without
    nazis breaking down my door) on that box and am not allowed ftp, ssh, or
    telnet access from where I posted from. I really thought that it would be
    an easy one to figure out. I mean, really - if there's a group of people
    that use regular expressions a lot, here they are. Any other group would
    give me a blank stare. I may have picked the wrong group, but not the wrong
    group of people.

    I do want to thank those of you who tactfully pointed me in the right
    direction and gave me bits of code. To the HUNDREDS of others that I
    bothered - sorry. To Abigail - I truly hope you find something better to do
    with your time that to pick on people asking for help.

    Shane
     
    ZafT, Oct 5, 2004
    #4
  5. Shane

    Anno Siegel Guest

    Sure we do, at least to the point where it's clear that it is
    off topic.
    Well, you failed. groveling-in-advance doesn't make you immune.
    Had to, eh? You could have gracefully conceded your error.
    So your miserable conditions entitle you to off-topic postings? Not so.
    What you essentially asked was, I know how to do it in Perl, how can I
    do it in TextPad (or whatever). That got you blank stares. Amazed?

    Anno
     
    Anno Siegel, Oct 5, 2004
    #5
  6. Shane

    Shawn Corey Guest

    No bother at all. If I find you annoying, I'll use 'Ignore Thread' If I
    find you really annoying, I'll stop reading the newsgroup.

    --- Shawn
     
    Shawn Corey, Oct 5, 2004
    #6
  7. Shane

    Eric Bohlman Guest

    [I'm making more of a general observation here and not trying to single you
    out personally, since you are by no means the first person to make this
    mistake on Usenet]

    I've come to the conclusion that one of the most common, if not *the* most
    common, sources of friction in technical Usenet groups is the fact that
    many people simply have no sense of just how much they're taking for
    granted when they ask a question. In this case, for example, it was quite
    obvious to the OP what the limitations of his environment were, but there
    was *no* realistic way anyone reading his post could have known about them.
    In fact, if he had *explicitly* stated those limitations, his query would
    have been *much* better received here (even if most of the responses took
    the form of "I can't help you out").

    It would seem that the _reductio ad absurdum_ of taking things for granted
    would be asking "my program doesn't work. What's wrong with it?" without
    giving *any* details of what the program consisted of, what it was supposed
    to do, and what it was doing that it wasn't supposed to do or what it
    wasn't doing that it was supposed to do. And yet we get *exactly* that
    several times a week!

    Asking other people to help you solve a problem is very much like
    delegating a task to someone else. When you do something yourself, you
    take into consideration a whole bunch of "background knowledge" that you
    often aren't even explicitly aware of. But when you ask someone else to do
    it, they won't be able to (at least not to do it well) unless you
    *explictly* state all the background details. That's part of the reason
    why there's such a common perception that "if you want it done right, you
    have to do it yourself" (another reason is that we tend, without being
    consciously aware of it, to forgive our own slipups more than other
    people's; this is part of a more general tendency that's so universal that
    psychologists call it "the fundamental error of attribution").

    And similarly, when you need someone else's help with a problem, you really
    need to (if the someone else is going to be able to give you meaningful
    help) make a *conscious effort* to determine which "background details" are
    important and which aren't, and to *state the important details
    explicitly*. If you don't make such an effort (and it *is* an effort, and
    it doesn't come "naturally" to anybody), then you will almost certainly err
    by omitting the very details that point to the solution (in fact, making
    the effort often results in your solving the problem yourself because it
    makes you aware of things that you overlooked).

    Now you've got to realize that this phenomenon (posters asking questions
    that could only be answered by a mind-reader) happens *so* frequently here
    that anyone one poster who does it might well be the "straw that broke the
    camel's back" for whoever is reading it. A very tall person who blew up at
    the first person to ask him "how's the weather up there" would indeed be
    oversensitive and ill-tempered, but he'd have to be a saint not to show at
    least some signs of annoyance when he hears it for the twentieth time since
    he woke up and it's still three hours until lunchtime.

    BTW, when we ask someone to show what they've tried so far, we're not being
    snotty. It's just that we don't want to waste our time suggesting "try
    this" only to hear "I already did." And for that matter, until we know
    what you tried, we have *no* way of knowing how those attempts could have
    gone wrong.
     
    Eric Bohlman, Oct 5, 2004
    #7

  8. If you apologize before you act rude then nobody will think badly of you?

    It appears that you are not a student of human nature.

    If you don't want to appear rude, then don't do rude activities.


    So you have been reading this newsgroup for a while then, since you
    seem quite confident that you know the size of the group's readership?

    We often get a hundred posts in a *single day* here, and that is
    only the people who speak up, there are likely a whole lot more
    who don't add posts.

    I am certain that at least 200 people read this newsgroup, so "hundreds"
    is completely accurate.

    (Pardon me, but I think your ignorance is showing.)


    When someone takes cuts in line, you think it is senseless to
    say something about it?

    It appears that you are not a student of human nature.

    Angst at off-topic posts helps everyone reading who contemplates
    making their own off-topic post to reconsider.

    If nobody says anything, that reenforces the rude behavior.


    Nobody is upset that you need help, that is a non-issue.

    What upsets people is that you do not need Perl help, yet here
    you are in the Perl newsgroup.

    ^^^^^^^^^^^

    No you didn't.

    You could have just said "Sorry, I won't do it again", and people
    would be able to see your future posts.

    Your poorly argued attempt at justifying your off-topic post is
    very likely to have more "cost" than "benefit".

    benefit: You feel better for a few hours

    cost: Many of the frequent-answerers will never see anymore of your posts.

    That seems a poor trade-off to me, perhaps you should have tried just
    a little harder to resist telling us how it should be here.


    Your sad environment has no effect on what is seen as socially
    acceptable on Usenet.


    That is much less likely to happen in the future now, as your
    followup pretty much demands that you be killfiled. So long!


    I have reason to doubt your sincerity there.


    To Anonymous Fool - I truly hope you find something better to do
    with your time than to (attempt to) realign the social dynamic that has
    developed here (and in nearly all newsgroups).
     
    Tad McClellan, Oct 5, 2004
    #8
  9. Shane

    P.R.Brady Guest

    [ ... snipped]

    Actually, I don't think that remark takes us forward at all, and I find
    it sad that you react angrily.

    I've asked lots of naive, sometimes stupid questions on the group, and
    always had very helpful answers, though occasionally had a tactful
    pointer to perldoc which is perfectly valid.

    Abigail is always in the forefront of helpful replies and I wouldn't
    want him to stop!

    Phil
     
    P.R.Brady, Oct 5, 2004
    #9
  10. Shane

    Shane Guest

    Thanks for understanding. Not to mean that I will make a habit of off
    topic posts :)

    Really, sorry for the off topic post all. Again, I just didn't know
    where else to go that I may actually get an answer. This has been a
    pretty friendly newsgroup in the past, but I suppose that's because I
    have never posted anything related to anything other than perl.

    Shane
     
    Shane, Oct 5, 2004
    #10
  11. (Shane) wrote in
    So, apparently, you did not really need an answer. I did point out that you
    should try comp.editors but I don't see a post from you.

    I have a feeling your posts might not be seen by a lot of people from this
    point on.

    Sinan.
     
    A. Sinan Unur, Oct 5, 2004
    #11
  12. Shane

    ZafT Guest

    # I tried to post this via dbforums hours ago, but it is not showing up.
    Anyway...

    Actually, I really did need the help, but google takes a while to update
    postings and I didn't see your message until I had already recieved an email
    back from a friend. In fact, google has not even posted the message I am
    replying to yet - I had to sign up for dbforums today to reply to you right
    now). Did I mention that I have no NNTP access here either? heh. In case you
    are really interested, or don't believe that I actually did find what I was
    looking for, here is what you need to do it in Textpad and UltraEdit.

    Textpad

    Search for:
    \(foo\?[0-9]+\)\(["]*\)

    Replace with:
    \1.txt"


    UltraEdit

    Search for:
    ^(foo?*^)"

    Replace with:
    ^1.txt"

    I hope you believe that I was not posting just to waste your time - your
    help is truly appeciated, and I made a sincere effort in an earlier posting
    to thank you for answering my request with a tactful point in the right
    direction. Just because I did not post after I finally saw your reply does
    not mean I did not need the help when I asked for it. I just happened to
    actually get the help before I got your post. However, the group will be
    thankful that you have told me the correct place to post these types of
    questions.

    I hope that this convinces you that I did not intend to waste anyone's time.
    Is there some sort of re-initiation I have to go through to get off
    everyone's ignore list, or do I have to assume a new identity?


    Shane
     
    ZafT, Oct 6, 2004
    #12

  13. Each person maintains their own ignore list, so you have to convince
    each person to take your address back out.

    I remain unconvinced, I saw profound "bad attitude" in your followup,
    so you are staying in _my_ list at least. There are plenty of questions
    for me to answer from folks that have not proven themselves less worthy.

    My policy is once an address goes in, it never comes out.

    (which seemed draconian when the possible "transgressions" were
    unwritten. This was what motivated me to write them down in the
    Posting Guidelines.
    )


    That is about the only way.

    (But I'll point out that if _I_ recognize you using a new address, I'll
    simply make another entry for the new address too.
    My aim is to spend no more of my time on questions from you, I've
    already spent "the limit".
    )
     
    Tad McClellan, Oct 6, 2004
    #13
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.