Afficher un message
Vieux 23/08/2006, 16h30   #3
Xicheng Jia
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed: How do you match a string containing square brackets AND hyphens?

Dave S. wrote:
> The streaming editor (sed) allows us to use the metacharacters "[" and
> "]" to match any one of a number of characters. According to the
> Pattern Matching chapter in O'Reilly's book Unix in a Nutshell by
> Daniel Gilly, "A hyphen or close bracket (]) as the first character is
> treated as a member of the list."
>
> That's great, but what if I need to match a string that may contain
> brackets AND hypens?
>
> I need to match a C++ variable name or constant that may include any of
> these characters:
> A-Z
> a-z
> 0-9
> - (hypen)
> _ (underscore)
> > (as in ->)

> [ and ]
> . (dot)
>
> Here is what I'd like to be able to do:
> s/something\([A-Za-z0-9_->\[\]\.]*\)the_rest/something_else \1
> the_rest/
>
> That does not work.
>
> What can I do?


try this: []A-Z0-9_.>a-z[-]

> Why is simply escaping the [ and ] characters in the list not good
> enough?


This looks quite different from Perl's regex where you can use
backslashes to escape them and then put them in the middle of the
class-set.

--
XC

  Réponse avec citation
 
Page generated in 0,05253 seconds with 9 queries