Regular Expression help please

S

Shane

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
 
A

A. Sinan Unur

(e-mail address removed) (Shane) wrote in
Hi,

I'm sure this message doesn't belong here exactly,

You might want to head on over to comp.editors for help with text editors.

Sinan.
 
T

Tad McClellan

Shane said:
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"

about how to do it in Perl and just write a script to do it.


perl -p -i~ -e 's/(foo\?[^"]+)"/$1.txt"/g' file
 
Z

ZafT

Asking on Usenet, and bothering hundreds of other people just to avoid
writing a one-liner in Perl, now *that* is overkill.

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
 
A

Anno Siegel

ZafT said:
First of all, you don't have to read the frickin post.

Sure we do, at least to the point where it's clear that it is
off topic.
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.

Well, you failed. groveling-in-advance doesn't make you immune.
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.

Had to, eh? You could have gracefully conceded your error.
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.

So your miserable conditions entitle you to off-topic postings? Not so.
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.

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
 
S

Shawn Corey

ZafT said:
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

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
 
E

Eric Bohlman

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'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.
 
T

Tad McClellan

ZafT said:
and groveled at the group's feet
for mercy to avoid getting flamed.


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.

Second, how much of a bother is it to post a message. Hundreds? I think
not.


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.)

If so, then you just bothered the same group of people by posting a
reply- a senseless one I might add.


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.

At least I really needed some help.


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.

Now I just had to bother them all over again just to bitch at you.
^^^^^^^^^^^

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.

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.


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

I do want to thank those of you who tactfully pointed me in the right
direction and gave me bits of code.


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

To the HUNDREDS of others that I
bothered - sorry.


I have reason to doubt your sincerity there.

To Abigail - I truly hope you find something better to do
with your time that to pick on people asking for help.


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).
 
P

P.R.Brady

ZafT said:
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.

[ ... 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
 
S

Shane

Shawn Corey said:
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

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
 
A

A. Sinan Unur

(e-mail address removed) (Shane) wrote in
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.

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.
 
Z

ZafT

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 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
 
T

Tad McClellan

Is there some sort of re-initiation I have to go through to get off
everyone's ignore list,


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.
)

or do I have to assume a new identity?


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".
)
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Please, help me. 1
Help please 8
Code help please 4
Please help me!!! 3
Malicious Coding Help Please 5
Regular expression help 2
Requesting regular expression help 12
Recursion regular expression (xtended) 1

Members online

Forum statistics

Threads
473,743
Messages
2,569,477
Members
44,898
Latest member
BlairH7607

Latest Threads

Top