For Programmers: Free Programming Magazines  


Home > Archive > AWK > June 2004 > Question regular expression...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Question regular expression...
Michael B.

2004-06-10, 3:55 pm

Hi,

I'm new to awk and regular expressions. What I need is a regular
expression that removes everything between [ and ], inclusive the
brackets.

For example: The string "Hi this is a [little] test" should be "Hi
this is a test" afterwards.

How do I do that?

Thanks for any help!

Michael
Ed Morton

2004-06-10, 8:57 pm



Michael B. wrote:
> Hi,
>
> I'm new to awk and regular expressions. What I need is a regular
> expression that removes everything between [ and ], inclusive the
> brackets.
>
> For example: The string "Hi this is a [little] test" should be "Hi
> this is a test" afterwards.
>
> How do I do that?


That wouldn't just remove the part within the [...], it also removes a
white spacce. This removes the part within []:

awk '{sub("\\[.*\\]","");print}'

There's various ways to remove the white space.

Ed.

> Thanks for any help!
>
> Michael


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com