Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Regular expression question

2 views
Skip to first unread message

Kauser Ali Karim

unread,
Jan 26, 2001, 1:03:34 PM1/26/01
to

Hi,

I need to get rid of the first fifteen charcters
(which are uppercase letters and numbers) of a line. How
would I do this using regular expressions.

I know that something like this would work,
but would only get rid of the first character.

s/[^A-Z0-9]//


Any help would be appreciated

Thanks.

Kauser
------


Barry Margolin

unread,
Jan 26, 2001, 1:46:04 PM1/26/01
to
In article <Pine.GSO.4.30.01012...@koala.cdf>,

Kauser Ali Karim <g9ka...@cdf.toronto.edu> wrote:
>I need to get rid of the first fifteen charcters
>(which are uppercase letters and numbers) of a line. How
>would I do this using regular expressions.
>
>I know that something like this would work,
>but would only get rid of the first character.
>
>s/[^A-Z0-9]//

s/^.\{15\}//

--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

nob...@mail.com

unread,
Jan 26, 2001, 2:00:25 PM1/26/01
to
Kauser Ali Karim <g9ka...@cdf.toronto.edu> writes:

> Subject: Regular expression question

Regular expressions are a wide subject. Conder putting more info in
you subject line. To make space you should omit the word "question".

> Newsgroups: comp.unix.questions,comp.lang.perl.misc

What does this have to do with Unix?

> I need to get rid of the first fifteen charcters
> (which are uppercase letters and numbers) of a line. How
> would I do this using regular expressions.
>
> I know that something like this would work,
> but would only get rid of the first character.
>
> s/[^A-Z0-9]//

No, it would get rid of the first character that was not a
upperalphanumeric.

s/^[A-Z0-9]{15}//;

Of course if you know that the first 15 characters will always be
upperalphanumeric then you can simply use substr().

> Any help would be appreciated

Perl regular expressions are documented in the perlre manpage.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\

Kurt J. Lanza

unread,
Jan 26, 2001, 3:11:57 PM1/26/01
to
Kauser Ali Karim wrote:
>
> Hi,
>
> I need to get rid of the first fifteen charcters
> (which are uppercase letters and numbers) of a line. How
> would I do this using regular expressions.
>
> I know that something like this would work,
> but would only get rid of the first character.
>
> s/[^A-Z0-9]//
>

S/^.{15}//

"man regexp" for a complete description of REs.

Garry Williams

unread,
Jan 27, 2001, 12:00:24 AM1/27/01
to
On Fri, 26 Jan 2001 15:11:57 -0500, Kurt J. Lanza <k...@inforonics.com> wrote:
>Kauser Ali Karim wrote:
>>
>> Hi,
>>
>> I need to get rid of the first fifteen charcters
>> (which are uppercase letters and numbers) of a line. How
>> would I do this using regular expressions.
>>
>> I know that something like this would work,
>> but would only get rid of the first character.
>>
>> s/[^A-Z0-9]//
>>
>
> S/^.{15}//
^
^


s/^.{15}//;

--
Garry Williams

Robert Katz

unread,
Jan 30, 2001, 3:21:58 AM1/30/01
to
Garry Williams wrote:
>
> On Fri, 26 Jan 2001 15:11:57 -0500,
> Kurt J. Lanza <k...@inforonics.com> wrote:
> >Kauser Ali Karim wrote:
> >> I need to get rid of the first fifteen charcters
> >> ...

> >
> > S/^.{15}//
> ^
> ^
>
> s/^.{15}//;

^ ^

$ sed 's/^.\{15\}//'

---Robert

Bart Lateur

unread,
Jan 30, 2001, 5:32:11 AM1/30/01
to
Barry Margolin wrote:

>s/^.\{15\}//

That is an understandable mistake, if you use more other regexp packages
(like sed/grep/awk/lex, or search tools inside text editors) than Perl.
Perl has the meaning of '\{' vs. '{', and of '\(' and '(', reversed
compared to many of those other packages. For example, simple grep uses
'\(' for grouping, while egrep uses '('.

(source: "Mastering Regular Expressions", Jeffrey Friedl)

--
Bart.

Barry Margolin

unread,
Jan 30, 2001, 11:27:49 AM1/30/01
to
In article <135d7t83bpgp8nr4i...@4ax.com>,

Bart Lateur <bart....@skynet.be> wrote:
>Barry Margolin wrote:
>
>>s/^.\{15\}//
>
>That is an understandable mistake, if you use more other regexp packages
>(like sed/grep/awk/lex, or search tools inside text editors) than Perl.

I read the message in comp.unix.questions and didn't notice that it was
x-posted to comp.lang.perl.misc, so I answered in a sed/grep frame of mind.

0 new messages